@bitefoundry/outlook 0.0.0-stage → 0.1.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.
- package/README.md +144 -2
- package/bin/outlook.js +130 -0
- package/docs/NPM.md +236 -0
- package/package.json +44 -4
- package/scripts/postinstall.mjs +266 -0
package/README.md
CHANGED
|
@@ -1,3 +1,145 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# `outlook`
|
|
4
|
+
|
|
5
|
+
**Blazing-fast Microsoft Outlook terminal client & AI agent toolkit — Mail, Calendar, To Do, and Contacts in one native Rust binary.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@bitefoundry/outlook)
|
|
8
|
+
[](docs/NPM.md)
|
|
9
|
+
[](https://ratatui.rs)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Highlights
|
|
21
|
+
|
|
22
|
+
| Pillar | What You Get |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| **Minimal-Chrome TUI** | 3-tier responsive `ratatui` workspace across **Mail** (`1`), **Calendar** (`2`), and **Microsoft To Do** (`3`) with HTML-rendered email preview, inline `href` toggle (`h`), Link Extractor (`u`), quoted-reply folding (`z`), structured Compose modal (`c`), `zoxide` File Picker (`Ctrl+F`), and `Ctrl+K` Omni-Switcher. |
|
|
25
|
+
| **High-Res Terminal Images** | Native inline rendering for attached and `cid:`/`https://` email images across **Kitty**, **iTerm2 (`OSC 1337`)**, **Sixel (`DCS q`)**, and **24-bit Half-Blocks (`▀`)** fallback with live zoom (`+`/`-`/`0`) and protocol cycling (`p`). |
|
|
26
|
+
| **Local SQLite FTS5 + IPC Daemon** | Bundled SQLite WAL + FTS5 cache (`cache.db`) with incremental delta sync, `$batch` neighbor hydration, 0ms optimistic triage (`archive`, `flag`, `mark-read`, `complete`), offline search, and sub-5ms CLI reads via `outlook daemon`. |
|
|
27
|
+
| **4-in-1 Agent Interface** | One static binary (Windows, macOS, Linux **GLIBC 2.28 / AlmaLinux 8+**) delivers **TUI**, scriptable **CLI (`--json`)**, **Axum HTTP REST API (`outlook serve`, `:3939`)**, and **stdio MCP server (`outlook mcp`, 20 tools)**. |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# 1. Install globally via npm (links prebuilt native binary, zero Node runtime overhead)
|
|
35
|
+
npm i -g @bitefoundry/outlook
|
|
36
|
+
|
|
37
|
+
# 2. Authenticate with Microsoft Entra ID (or automatically reuse your @bitefoundry/teams M365 session!)
|
|
38
|
+
outlook login
|
|
39
|
+
|
|
40
|
+
# 3. Launch the interactive TUI
|
|
41
|
+
outlook
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> **Shared M365 Session & Token Brokers:** When `share_m365_auth = true` (default), `outlook` seamlessly reuses or upgrades an existing `@bitefoundry/teams` session without a second browser login. Also supports `--device-code`, `OUTLOOK_ACCESS_TOKEN`, `OUTLOOK_TOKEN_FILE`, `OUTLOOK_TOKEN_REFRESH_CMD` (`az account get-access-token`), and custom Entra ID apps. Run `outlook whoami` or `outlook doctor --online` for JWT scope diagnostics, and `outlook update` for one-click SHA-256 verified self-updates.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Keybindings Cheat Sheet
|
|
49
|
+
|
|
50
|
+
| Key | Context | Action |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `1` / `2` / `3` (`Alt+1..3`) | Global | Switch **Mail** / **Calendar** / **To Do Tasks** tabs |
|
|
53
|
+
| `Ctrl+K` | Global | **Omni-Switcher / Command Palette** (`>` commands, `#` folders, `@` contacts, `/` search) |
|
|
54
|
+
| `j` / `k` / `↑` / `↓` | Global | Navigate folders, message list, calendar agenda, tasks, or reading pane |
|
|
55
|
+
| `Tab` / `Enter` / `Esc` | Global | Cycle pane focus (`Folders ↔ List ↔ Reader`) or close modal |
|
|
56
|
+
| `c` / `r` / `R` / `f` | Mail | **Compose** / **Reply** / **Reply-All** / **Forward** (Markdown + `Ctrl+F` attach + `Ctrl+V` image) |
|
|
57
|
+
| `e` / `g` / `m` / `Del` | Mail | **Archive** / **Flag** / **Move to folder** / **Delete** (0ms optimistic updates) |
|
|
58
|
+
| `h` / `u` / `z` | Mail Reader | Toggle inline `href` URLs / open **Link Extractor** / fold quoted reply history |
|
|
59
|
+
| `t` / `F` / `U` | Mail | Toggle **Thread grouping** / **Focused Inbox** / **Unread filter** |
|
|
60
|
+
| `v` / `Alt+v` / `d` | Mail Reader | High-res **Inline Image Preview** / download latest attachment (`A` for picker) |
|
|
61
|
+
| `n` / `a` / `y` / `x` | Calendar | **New Event** / RSVP **Accept** (`a`), **Tentative** (`y`), **Decline** (`x`) |
|
|
62
|
+
| `Space` / `n` | Tasks | Toggle To Do completion (`Space`) / create new task or list (`n`) |
|
|
63
|
+
| `/` / `Ctrl+D` / `Ctrl+B` | Global | Search mail (FTS5 + Graph KQL) / toggle **Cozy / Compact** density / toggle sidebar |
|
|
64
|
+
| `Ctrl+,` / `?` / `Ctrl+Q` | Global | **Settings** / full help overlay / safe quit |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## CLI, HTTP API & MCP
|
|
69
|
+
|
|
70
|
+
### CLI Examples
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Mail: inspect inbox, read, reply, and send Markdown with attachments
|
|
74
|
+
outlook mail --folder inbox --unread --limit 20 --json
|
|
75
|
+
outlook read AAMkAGI2... --mark-read
|
|
76
|
+
outlook send --to elena.park@acme.dev --subject "v2.4 Release" \
|
|
77
|
+
--body "**All canary checks passed.** See attached benchmarks." \
|
|
78
|
+
--attach ./v24-benchmarks.pdf --importance high
|
|
79
|
+
|
|
80
|
+
# Calendar & To Do: view agenda, schedule Teams meeting, RSVP, and manage tasks
|
|
81
|
+
outlook calendar --days 7
|
|
82
|
+
outlook create-event --subject "Go / No-Go Review" \
|
|
83
|
+
--start "2026-11-20T14:00:00Z" --end "2026-11-20T14:45:00Z" \
|
|
84
|
+
--attendee elena.park@acme.dev --online
|
|
85
|
+
outlook add-task "Promote canary to 100%" --due 2026-11-20 --importance high
|
|
86
|
+
outlook daemon start
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Local HTTP REST API (`outlook serve`)
|
|
90
|
+
|
|
91
|
+
Start an Axum JSON server on `127.0.0.1:3939` (with live `/openapi.json` and optional `--api-key` auth):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
outlook serve --port 3939
|
|
95
|
+
curl http://127.0.0.1:3939/v1/mail/messages?folder=inbox&unread=true
|
|
96
|
+
curl -X POST http://127.0.0.1:3939/v1/mail/send \
|
|
97
|
+
-H "Content-Type: application/json" \
|
|
98
|
+
-d '{"to":["elena.park@acme.dev"],"subject":"Build green","markdown":"All checks passed!"}'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Full endpoint & schema docs: **[docs/API.md](docs/API.md)** · **[docs/openapi.yaml](docs/openapi.yaml)**
|
|
102
|
+
|
|
103
|
+
### MCP Server (`outlook mcp`)
|
|
104
|
+
|
|
105
|
+
Exposes **20 Microsoft Outlook tools** (`whoami`, `list_mail_folders`, `list_messages`, `get_message`, `send_mail`, `reply_mail`, `forward_mail`, `update_message`, `delete_message`, `download_attachment`, `search_mail`, `list_events`, `create_event`, `respond_event`, `delete_event`, `list_todo_lists`, `list_tasks`, `create_task`, `complete_task`, `search_contacts`) over newline-delimited stdio JSON-RPC 2.0:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Claude Code
|
|
109
|
+
claude mcp add outlook -- outlook mcp
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
// Claude Desktop / Cursor / Windsurf MCP config
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"outlook": {
|
|
117
|
+
"command": "outlook",
|
|
118
|
+
"args": ["mcp"]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Full tool schemas & client setups: **[docs/MCP.md](docs/MCP.md)** · **[docs/NPM.md](docs/NPM.md)**
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## `@bitefoundry` Enterprise Terminal Suite
|
|
129
|
+
|
|
130
|
+
| Package | Command | Domain | Interfaces |
|
|
131
|
+
| --- | --- | --- | --- |
|
|
132
|
+
| [`@bitefoundry/teams`](https://github.com/BiteFoundry/teams) | `teams` | Microsoft Teams (Chats, Channels, Threads, Presence) | TUI · CLI · HTTP · MCP |
|
|
133
|
+
| **`@bitefoundry/outlook`** *(this repo)* | `outlook` | Microsoft Outlook (Mail, Calendar, To Do, Contacts) | TUI · CLI · HTTP · MCP |
|
|
134
|
+
| [`@bitefoundry/onenote`](https://github.com/BiteFoundry/onenote) | `onenote` | Microsoft OneNote (Notebooks, Sections, Pages) | TUI · CLI · HTTP · MCP |
|
|
135
|
+
| [`@bitefoundry/sharepoint`](https://github.com/BiteFoundry/sharepoint) | `sharepoint` | SharePoint & OneDrive (Sites, Drives, Lists, Files) | TUI · CLI · HTTP · MCP |
|
|
136
|
+
| [`@bitefoundry/atlassian`](https://github.com/BiteFoundry/atlassian) | `atlassian` | Jira & Confluence (Issues, Boards, Sprints, Wiki) | TUI · CLI · HTTP · MCP |
|
|
137
|
+
| [`@bitefoundry/notion`](https://github.com/BiteFoundry/notion) | `notion` | Notion (Pages, Databases, Blocks, Comments) | TUI · CLI · HTTP · MCP |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## License & Disclaimer
|
|
142
|
+
|
|
143
|
+
Licensed under the [MIT License](LICENSE).
|
|
144
|
+
|
|
145
|
+
Unofficial terminal client for Microsoft Outlook. Not affiliated with, endorsed by, or sponsored by Microsoft Corporation.
|
package/bin/outlook.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawn } = require('node:child_process');
|
|
8
|
+
|
|
9
|
+
const SUPPORTED = [
|
|
10
|
+
'win32-x64',
|
|
11
|
+
'win32-arm64',
|
|
12
|
+
'darwin-x64',
|
|
13
|
+
'darwin-arm64',
|
|
14
|
+
'linux-x64',
|
|
15
|
+
'linux-arm64',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
function fail(message) {
|
|
19
|
+
process.stderr.write(`outlook: ${message}\n`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function formatLinuxGlibcHint() {
|
|
24
|
+
return [
|
|
25
|
+
'Prebuilt Linux binaries target GLIBC >= 2.28 (AlmaLinux 8 / RHEL 8 / Rocky Linux 8 / Ubuntu 20.04+ / Debian 10+).',
|
|
26
|
+
'If you are on an older glibc distribution (such as CentOS 7 with GLIBC < 2.28) or Alpine/musl,',
|
|
27
|
+
'build from source with Cargo instead:',
|
|
28
|
+
' cargo install --git https://github.com/BiteFoundry/outlook --locked',
|
|
29
|
+
'or clone the repository and run:',
|
|
30
|
+
' cargo build --release',
|
|
31
|
+
].join('\n');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const platform = process.platform;
|
|
35
|
+
const arch = process.arch;
|
|
36
|
+
const platformKey = `${platform}-${arch}`;
|
|
37
|
+
const packageName = `@bitefoundry/outlook-${platformKey}`;
|
|
38
|
+
const binaryName = platform === 'win32' ? 'outlook.exe' : 'outlook';
|
|
39
|
+
|
|
40
|
+
let packageDir = null;
|
|
41
|
+
try {
|
|
42
|
+
packageDir = path.dirname(require.resolve(`${packageName}/package.json`));
|
|
43
|
+
} catch {
|
|
44
|
+
packageDir = null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
48
|
+
|
|
49
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
50
|
+
const lines = [
|
|
51
|
+
`no prebuilt binary found for ${platformKey}.`,
|
|
52
|
+
'',
|
|
53
|
+
`Expected the optional dependency "${packageName}" to provide:`,
|
|
54
|
+
` ${binaryPath || `node_modules/${packageName}/bin/${binaryName}`}`,
|
|
55
|
+
'',
|
|
56
|
+
`Supported platforms: ${SUPPORTED.join(', ')}`,
|
|
57
|
+
'',
|
|
58
|
+
'Try one of:',
|
|
59
|
+
' npm install -g @bitefoundry/outlook --include=optional',
|
|
60
|
+
' npm install @bitefoundry/outlook --include=optional',
|
|
61
|
+
' npx --yes @bitefoundry/outlook',
|
|
62
|
+
'',
|
|
63
|
+
'If you are on an unsupported platform (for example Alpine/musl Linux),',
|
|
64
|
+
'build from source with Cargo:',
|
|
65
|
+
' cargo build --release',
|
|
66
|
+
];
|
|
67
|
+
fail(lines.join('\n'));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// npm does not guarantee the executable bit survives packaging, so make sure
|
|
71
|
+
// the binary is runnable before spawning it (only chmod when X_OK is missing).
|
|
72
|
+
if (platform !== 'win32') {
|
|
73
|
+
try {
|
|
74
|
+
fs.accessSync(binaryPath, fs.constants.X_OK);
|
|
75
|
+
} catch {
|
|
76
|
+
try {
|
|
77
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
78
|
+
} catch {
|
|
79
|
+
// Read-only install; spawn will report EACCES if the bit is missing.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
85
|
+
stdio: 'inherit',
|
|
86
|
+
windowsHide: false,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
child.on('error', (err) => {
|
|
90
|
+
if (
|
|
91
|
+
platform === 'linux' &&
|
|
92
|
+
(err.code === 'ENOENT' || /GLIBC_/i.test(String(err.message || '')))
|
|
93
|
+
) {
|
|
94
|
+
fail(
|
|
95
|
+
`failed to launch ${binaryPath}: ${err.message}\n\n${formatLinuxGlibcHint()}`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
fail(`failed to launch ${binaryPath}: ${err.message}`);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Forward termination signals to the child process.
|
|
102
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
103
|
+
const handler = () => {
|
|
104
|
+
if (!child.killed) {
|
|
105
|
+
try {
|
|
106
|
+
child.kill(signal);
|
|
107
|
+
} catch {
|
|
108
|
+
// Child already exited.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
process.on(signal, handler);
|
|
114
|
+
} catch {
|
|
115
|
+
// Signal not supported on this platform.
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
child.on('exit', (code, signal) => {
|
|
120
|
+
if (signal) {
|
|
121
|
+
const number = os.constants.signals[signal] || 1;
|
|
122
|
+
process.exit(128 + number);
|
|
123
|
+
}
|
|
124
|
+
if (platform === 'linux' && code === 127) {
|
|
125
|
+
process.stderr.write(
|
|
126
|
+
`outlook: binary exited with code 127 (missing shared library, dynamic linker, or GLIBC symbol version).\n${formatLinuxGlibcHint()}\n`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
process.exit(code === null ? 1 : code);
|
|
130
|
+
});
|
package/docs/NPM.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# npm distribution
|
|
2
|
+
|
|
3
|
+
`@bitefoundry/outlook` is distributed on npm as a small JavaScript launcher plus one
|
|
4
|
+
optional dependency per platform. The launcher resolves the prebuilt Rust binary
|
|
5
|
+
and execs it directly (with `scripts/postinstall.mjs` linking the native binary
|
|
6
|
+
into `bin/` and Windows shims for zero-Node-startup execution), so there is no
|
|
7
|
+
compiler, Node native addon, or network download during install.
|
|
8
|
+
|
|
9
|
+
The Rust crate is named `outlook-cli` and produces the pure **Microsoft Outlook**
|
|
10
|
+
binary (`outlook` / `outlook.exe`). The npm package is scoped as `@bitefoundry/outlook`
|
|
11
|
+
and installs the **`outlook`** command.
|
|
12
|
+
|
|
13
|
+
## Install and run
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
# one-off
|
|
17
|
+
npx @bitefoundry/outlook --version
|
|
18
|
+
|
|
19
|
+
# global install (installs `outlook`)
|
|
20
|
+
npm install -g @bitefoundry/outlook
|
|
21
|
+
outlook --version
|
|
22
|
+
|
|
23
|
+
# project-local
|
|
24
|
+
npm install @bitefoundry/outlook
|
|
25
|
+
npx outlook mail list
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
All workflows share the same Microsoft Entra ID login (or automatic M365 shared-session
|
|
29
|
+
bootstrap with `teams-cli`), SQLite WAL + FTS5 cache (`cache.db`), background sync
|
|
30
|
+
daemon (`outlook daemon start | status | stop | restart`), HTTP API (`outlook serve`,
|
|
31
|
+
default `127.0.0.1:3939`), MCP server (`outlook mcp`), and multi-protocol terminal image
|
|
32
|
+
preview (`Kitty` / `iTerm2` / `Sixel` / `Halfblock` via `outlook preview` and the TUI).
|
|
33
|
+
Read commands also support `--cached` / `--fast` for instant local cache reads, or run
|
|
34
|
+
with zero Graph round-trips while the daemon is warm:
|
|
35
|
+
|
|
36
|
+
- `outlook login`, `outlook whoami`, `outlook doctor --online`
|
|
37
|
+
- `outlook folders`, `outlook mail --folder inbox --limit 30`, `outlook read <message_id>`
|
|
38
|
+
- `outlook send`, `outlook reply`, `outlook forward`, `outlook mark`, `outlook move`, `outlook archive`, `outlook delete`
|
|
39
|
+
- `outlook calendar --days 7`, `outlook event <id>`, `outlook create-event`, `outlook rsvp`, `outlook delete-event`
|
|
40
|
+
- `outlook contacts --query <q>`, `outlook task-lists`, `outlook tasks`, `outlook add-task`, `outlook done`, `outlook delete-task`
|
|
41
|
+
- `outlook search`, `outlook download`, `outlook preview`, `outlook sync`, `outlook daemon <start|status|stop|restart>`, `outlook tui`, `outlook serve`, `outlook mcp`, `outlook update`
|
|
42
|
+
|
|
43
|
+
## Supported platforms
|
|
44
|
+
|
|
45
|
+
| npm package | OS | CPU | Rust target |
|
|
46
|
+
| ------------------------------- | ------- | ----- | ----------------------------------- |
|
|
47
|
+
| `@bitefoundry/outlook-win32-x64` | Windows | x64 | `x86_64-pc-windows-msvc` |
|
|
48
|
+
| `@bitefoundry/outlook-win32-arm64` | Windows | arm64 | `aarch64-pc-windows-msvc` |
|
|
49
|
+
| `@bitefoundry/outlook-darwin-x64` | macOS | x64 | `x86_64-apple-darwin` |
|
|
50
|
+
| `@bitefoundry/outlook-darwin-arm64` | macOS | arm64 | `aarch64-apple-darwin` |
|
|
51
|
+
| `@bitefoundry/outlook-linux-x64` | Linux | x64 | `x86_64-unknown-linux-gnu` (2.28) |
|
|
52
|
+
| `@bitefoundry/outlook-linux-arm64` | Linux | arm64 | `aarch64-unknown-linux-gnu` (2.28) |
|
|
53
|
+
|
|
54
|
+
Linux packages are cross-compiled in CI with `cargo-zigbuild` against **GLIBC 2.28** (`*.2.28`) and verified with `scripts/verify-glibc.mjs` plus an `almalinux:8` container smoke test, so prebuilt binaries run out of the box on **AlmaLinux 8 / RHEL 8+ / Rocky Linux 8+ / Ubuntu 20.04+ / Debian 10+**. Older glibc distributions (e.g., CentOS 7 with `GLIBC < 2.28`) and Alpine/musl Linux should build from source with Cargo (`cargo build --release`).
|
|
55
|
+
|
|
56
|
+
## How resolution works
|
|
57
|
+
|
|
58
|
+
`bin/outlook.js` looks up `@bitefoundry/outlook-<platform>-<arch>` through
|
|
59
|
+
`require.resolve`, then executes
|
|
60
|
+
`node_modules/@bitefoundry/outlook-<platform>-<arch>/bin/outlook` (or `outlook.exe` on
|
|
61
|
+
Windows) with `stdio: 'inherit'`. On `npm install`, `scripts/postinstall.mjs`
|
|
62
|
+
additionally replaces `bin/outlook.js` (Unix) or rewrites `.bin/outlook[.cmd|.ps1]`
|
|
63
|
+
(Windows) to invoke the native Rust executable directly without spawning Node.
|
|
64
|
+
Signals (`SIGINT`, `SIGTERM`, `SIGHUP`) are forwarded and the launcher exits
|
|
65
|
+
with the child's exit code. If the platform package is missing (for example
|
|
66
|
+
because optional dependencies were skipped), the launcher prints the supported
|
|
67
|
+
platforms and the `--include=optional` hint instead of a stack trace.
|
|
68
|
+
|
|
69
|
+
## Layout
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
package.json # @bitefoundry/outlook launcher package (bin: outlook)
|
|
73
|
+
bin/outlook.js # outlook launcher
|
|
74
|
+
scripts/postinstall.mjs # zero-Node native binary linker on npm install
|
|
75
|
+
outlook / outlook.cmd # repo-local Outlook launchers
|
|
76
|
+
npm/outlook-<platform>/ # one package per platform
|
|
77
|
+
package.json # os/cpu/files, same version as root
|
|
78
|
+
bin/outlook[.exe] # added by scripts/build-npm.mjs, never committed
|
|
79
|
+
scripts/build-npm.mjs # copy target/<triple>/release/outlook[.exe]
|
|
80
|
+
scripts/sync-version.mjs # Cargo.toml version -> all package.json files
|
|
81
|
+
scripts/verify-glibc.mjs # verify Linux ELF GLIBC <= 2.28 symbol ceiling
|
|
82
|
+
.github/workflows/release.yml # tag-triggered build, publish, GitHub Release
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Binaries are gitignored (`npm/*/bin/outlook*`). A clean checkout has empty
|
|
86
|
+
platform `bin/` directories until a build or `npm run build:npm` runs.
|
|
87
|
+
|
|
88
|
+
## Versioning
|
|
89
|
+
|
|
90
|
+
`Cargo.toml` (`[package].version`) is the single source of truth. To bump:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
# edit Cargo.toml [package].version
|
|
94
|
+
node scripts/sync-version.mjs
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The script updates the root `package.json`, every `npm/outlook-*/package.json`,
|
|
98
|
+
and the root `optionalDependencies` pins. It is idempotent; `--check` exits
|
|
99
|
+
non-zero if anything is stale. All packages must be published at the same
|
|
100
|
+
version because the root package pins its platform packages exactly.
|
|
101
|
+
|
|
102
|
+
Tag the release with a matching `v` prefix:
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
git tag v0.1.0
|
|
106
|
+
git push origin v0.1.0
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Publishing
|
|
110
|
+
|
|
111
|
+
Publishing is automated by `.github/workflows/release.yml`, which is triggered
|
|
112
|
+
by pushing a `v*` tag (or manually via `workflow_dispatch`).
|
|
113
|
+
|
|
114
|
+
1. Add a repository secret `NPM_TOKEN` (an npm automation token with publish
|
|
115
|
+
rights for the `@bitefoundry/outlook` packages).
|
|
116
|
+
2. Bump the version in `Cargo.toml`, run `node scripts/sync-version.mjs`,
|
|
117
|
+
commit, and push `v<version>`.
|
|
118
|
+
3. The workflow builds six targets, stages binaries into the platform
|
|
119
|
+
packages, uploads artifacts, publishes each platform package, publishes the
|
|
120
|
+
root package, and creates a GitHub Release with the archives, `outlook.exe`,
|
|
121
|
+
and `SHA256SUMS.txt`.
|
|
122
|
+
|
|
123
|
+
The publish job verifies that the tag matches the package version and that all
|
|
124
|
+
six platform packages contain a binary before publishing anything. Platform
|
|
125
|
+
packages are published first so the root package's `optionalDependencies` can
|
|
126
|
+
resolve immediately.
|
|
127
|
+
|
|
128
|
+
Manual publish (matching order):
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
node scripts/sync-version.mjs --check
|
|
132
|
+
for dir in npm/outlook-*; do npm publish "$dir" --access public; done
|
|
133
|
+
npm publish --access public
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Local validation
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
# stage the current host binary (Windows example)
|
|
140
|
+
node scripts/build-npm.mjs --target x86_64-pc-windows-msvc
|
|
141
|
+
node bin/outlook.js --version
|
|
142
|
+
|
|
143
|
+
npm pack --dry-run
|
|
144
|
+
npm pack --dry-run ./npm/outlook-win32-x64
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`node scripts/build-npm.mjs` with no arguments uses the host target and falls
|
|
148
|
+
back to `target/release/` when a plain `cargo build --release` was used.
|
|
149
|
+
`--all` attempts every supported target and warns about the ones not built on
|
|
150
|
+
the current host.
|
|
151
|
+
|
|
152
|
+
## External token brokers, M365 bootstrap & token scopes
|
|
153
|
+
|
|
154
|
+
When using an external Microsoft Graph token broker (`tc-auth`, `az account get-access-token`, Vault CLI, etc.), configure `token_file` / `token_refresh_cmd` instead of shell wrappers (avoids `cmd.exe` 1023-char `set /p` truncation and `.ps1`/`.cmd` shim issues). Setting `OUTLOOK_TOKEN_FILE` (`token_file`) or `OUTLOOK_ACCESS_TOKEN` automatically skips OS keyring reads.
|
|
155
|
+
|
|
156
|
+
When `share_m365_auth = true` (default; `OUTLOOK_SHARE_M365_AUTH=true`), `outlook` can also bootstrap from an existing `TEAMS_TOKEN_FILE` or `teams-cli` stored session if no `outlook-cli` token is configured yet.
|
|
157
|
+
|
|
158
|
+
### Required Microsoft Graph delegated scopes
|
|
159
|
+
|
|
160
|
+
Pure Outlook requests only Microsoft Outlook & Graph core scopes:
|
|
161
|
+
|
|
162
|
+
`offline_access`, `User.Read`, `User.ReadBasic.All`, `Mail.ReadWrite`, `Mail.Send`, `Calendars.ReadWrite`, `Contacts.ReadWrite`, `Tasks.ReadWrite`
|
|
163
|
+
|
|
164
|
+
Run `outlook whoami` or `outlook doctor` to inspect JWT `scp`/`roles` claims automatically.
|
|
165
|
+
|
|
166
|
+
### 1. `config.toml` (recommended persistent setup)
|
|
167
|
+
|
|
168
|
+
```toml
|
|
169
|
+
# Windows: %APPDATA%\outlook-cli\config.toml
|
|
170
|
+
# Linux/macOS: ~/.config/outlook-cli/config.toml
|
|
171
|
+
token_file = "~/.cursor/tc-auth/access_token"
|
|
172
|
+
token_refresh_cmd = "python ~/.cursor/tc-auth/graph-auth.py refresh"
|
|
173
|
+
token_refresh_mins = 5
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 2. Environment variables
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
export OUTLOOK_TOKEN_FILE="$HOME/.cursor/tc-auth/access_token"
|
|
180
|
+
export OUTLOOK_TOKEN_REFRESH_CMD="python $HOME/.cursor/tc-auth/graph-auth.py refresh"
|
|
181
|
+
export OUTLOOK_TOKEN_REFRESH_MINS=5
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 3. Azure CLI (`az account get-access-token`) JSON/stdout integration
|
|
185
|
+
|
|
186
|
+
If `token_file` is omitted, `token_refresh_cmd` stdout (raw JWT or Azure CLI camelCase JSON `accessToken` / `expiresOn`) is parsed and cached in memory:
|
|
187
|
+
|
|
188
|
+
```toml
|
|
189
|
+
token_refresh_cmd = "az account get-access-token --resource https://graph.microsoft.com --output json"
|
|
190
|
+
token_refresh_mins = 5
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Key environment variables
|
|
194
|
+
|
|
195
|
+
| Variable | Summary |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| `OUTLOOK_ACCESS_TOKEN` | Static Bearer token override (automatically skips OS keyring) |
|
|
198
|
+
| `OUTLOOK_TOKEN_FILE` | External token file path (raw JWT or JSON; skips OS keyring) |
|
|
199
|
+
| `OUTLOOK_TOKEN_REFRESH_CMD` | Shell command run to refresh expiring/`401` tokens |
|
|
200
|
+
| `OUTLOOK_TOKEN_REFRESH_MINS` | Refresh lead window in minutes before expiry (default `5`) |
|
|
201
|
+
| `OUTLOOK_SHARE_M365_AUTH` | Share/bootstrap M365 token session from `TEAMS_TOKEN_FILE` or `teams-cli` (default `true`) |
|
|
202
|
+
| `OUTLOOK_DISABLE_KEYRING=1` | Disable OS keyring and use `credentials.json` only |
|
|
203
|
+
| `OUTLOOK_CLIENT_ID` | Override Entra ID application client ID (falls back to `TEAMS_CLIENT_ID`, `AZURE_CLIENT_ID`) |
|
|
204
|
+
| `OUTLOOK_TENANT_ID` | Override Entra ID tenant ID (default `common`; falls back to `TEAMS_TENANT_ID`, `AZURE_TENANT_ID`) |
|
|
205
|
+
| `OUTLOOK_CONFIG_DIR` | Override config/credentials directory |
|
|
206
|
+
| `OUTLOOK_DATA_DIR` | Override SQLite cache (`cache.db`) directory |
|
|
207
|
+
| `OUTLOOK_NO_BROWSER` | Disable automatic browser launch during login (`1` / `true`) |
|
|
208
|
+
| `OUTLOOK_CLI_CACHE_SECS` | CLI read cache TTL in seconds (default `0`; `--cached` / `--fast` forces cache-first reads) |
|
|
209
|
+
| `OUTLOOK_AUTO_DAEMON` | Auto-start/attach to the background sync daemon (`1` / `true`, or `config.toml`: `auto_daemon = true`, default `false`) |
|
|
210
|
+
| `OUTLOOK_IMAGE_PROTOCOL` | Terminal image protocol override (`auto`, `kitty`, `iterm2`, `sixel`, `halfblock`) |
|
|
211
|
+
| `OUTLOOK_GITHUB_REPO` | Override GitHub `owner/repo` used by `outlook update` (default `BiteFoundry/outlook`) |
|
|
212
|
+
| `OUTLOOK_GITHUB_TOKEN` | GitHub token for private release checks in `outlook update` |
|
|
213
|
+
|
|
214
|
+
## Troubleshooting
|
|
215
|
+
|
|
216
|
+
- **`no prebuilt binary found for <platform>-<arch>`** — the optional
|
|
217
|
+
dependency was skipped. Reinstall with
|
|
218
|
+
`npm install -g @bitefoundry/outlook --include=optional` or
|
|
219
|
+
`npm install @bitefoundry/outlook --include=optional`. Check that your npm config
|
|
220
|
+
does not set `omit=optional`.
|
|
221
|
+
- **`EBADPLATFORM` / package skipped** — npm installs only the matching
|
|
222
|
+
`os`/`cpu` package. Cross-installing (for example x64 Node on ARM Windows via
|
|
223
|
+
emulation) still reports the Node architecture, so install under the native
|
|
224
|
+
Node build.
|
|
225
|
+
- **Older Linux (`GLIBC < 2.28`, e.g. CentOS 7) or Alpine/musl Linux** — prebuilt Linux binaries require **GLIBC >= 2.28** (AlmaLinux 8 / RHEL 8+ / Rocky Linux 8+ / Ubuntu 20.04+ / Debian 10+). On older glibc or musl systems, build from source with Cargo (`cargo build --release`).
|
|
226
|
+
- **macOS Gatekeeper** — npm-installed binaries are not notarized. If macOS
|
|
227
|
+
blocks execution, allow the binary in System Settings → Privacy & Security, or
|
|
228
|
+
build from source.
|
|
229
|
+
- **Corporate proxy/firewall** — `npx @bitefoundry/outlook` performs a registry
|
|
230
|
+
download each time unless cached; use a global install for offline-friendly
|
|
231
|
+
use.
|
|
232
|
+
- **Verify the binary** —
|
|
233
|
+
`node -p "require.resolve('@bitefoundry/outlook-win32-x64/package.json')"`
|
|
234
|
+
(adjust for your platform) shows which platform package npm selected.
|
|
235
|
+
- **Tag push did not publish** — check the publish job log; a tag/version
|
|
236
|
+
mismatch or a missing `NPM_TOKEN` fails the job before any publish.
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitefoundry/outlook",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Microsoft Outlook terminal client & AI agent toolkit — Mail, Calendar, Tasks & Contacts (CLI, TUI, HTTP API, MCP)",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/BiteFoundry/outlook.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"bin": {
|
|
11
|
+
"outlook": "bin/outlook.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/outlook.js",
|
|
15
|
+
"scripts/postinstall.mjs",
|
|
16
|
+
"docs/NPM.md",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"microsoft-outlook",
|
|
24
|
+
"outlook",
|
|
25
|
+
"microsoft-365",
|
|
26
|
+
"microsoft-graph",
|
|
27
|
+
"mail",
|
|
28
|
+
"calendar",
|
|
29
|
+
"cli",
|
|
30
|
+
"tui",
|
|
31
|
+
"mcp"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
35
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
36
|
+
"build:npm": "node scripts/build-npm.mjs"
|
|
37
|
+
},
|
|
38
|
+
"optionalDependencies": {
|
|
39
|
+
"@bitefoundry/outlook-win32-x64": "0.1.0",
|
|
40
|
+
"@bitefoundry/outlook-win32-arm64": "0.1.0",
|
|
41
|
+
"@bitefoundry/outlook-darwin-x64": "0.1.0",
|
|
42
|
+
"@bitefoundry/outlook-darwin-arm64": "0.1.0",
|
|
43
|
+
"@bitefoundry/outlook-linux-x64": "0.1.0",
|
|
44
|
+
"@bitefoundry/outlook-linux-arm64": "0.1.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Zero-Node-Process npm native binary linker.
|
|
3
|
+
//
|
|
4
|
+
// On Unix (linux/darwin): replaces installed `bin/outlook.js` with
|
|
5
|
+
// hardlinks/symlinks directly to `@bitefoundry/outlook-<platform>-<arch>/bin/outlook` so npm's
|
|
6
|
+
// bin symlink execve's the native Rust binary directly (0ms Node startup, 0MB Node RSS).
|
|
7
|
+
//
|
|
8
|
+
// On Windows (win32): creates an NTFS hardlink (fallback copy) `bin/outlook.exe`
|
|
9
|
+
// and rewrites npm's `.bin/outlook[.cmd|.ps1]` shims when present to invoke
|
|
10
|
+
// `outlook.exe` directly without spawning `node.exe`.
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
const BIN_NAMES = ['outlook'];
|
|
18
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
19
|
+
|
|
20
|
+
function linkOrCopyFile(source, destination) {
|
|
21
|
+
const tmp = `${destination}.tmp-${process.pid}`;
|
|
22
|
+
try {
|
|
23
|
+
fs.rmSync(tmp, { force: true });
|
|
24
|
+
} catch {
|
|
25
|
+
// Ignore cleanup errors on nonexistent temp paths.
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
fs.linkSync(source, tmp);
|
|
29
|
+
} catch {
|
|
30
|
+
fs.copyFileSync(source, tmp);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
fs.renameSync(tmp, destination);
|
|
34
|
+
} catch {
|
|
35
|
+
try {
|
|
36
|
+
fs.rmSync(destination, { force: true });
|
|
37
|
+
} catch {
|
|
38
|
+
// Ignore; renameSync below will surface or fail safely.
|
|
39
|
+
}
|
|
40
|
+
fs.renameSync(tmp, destination);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function replaceJsWithNativeLinkUnix(binaryPath, destinationJs) {
|
|
45
|
+
const tmp = `${destinationJs}.tmp-${process.pid}`;
|
|
46
|
+
try {
|
|
47
|
+
fs.rmSync(tmp, { force: true });
|
|
48
|
+
} catch {
|
|
49
|
+
// Ignore cleanup errors.
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
fs.linkSync(binaryPath, tmp);
|
|
53
|
+
} catch {
|
|
54
|
+
try {
|
|
55
|
+
fs.rmSync(tmp, { force: true });
|
|
56
|
+
} catch {
|
|
57
|
+
// Ignore cleanup errors.
|
|
58
|
+
}
|
|
59
|
+
fs.symlinkSync(binaryPath, tmp);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
fs.renameSync(tmp, destinationJs);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
try {
|
|
65
|
+
fs.rmSync(tmp, { force: true });
|
|
66
|
+
} catch {
|
|
67
|
+
// Ignore cleanup errors.
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function collectWindowsShimDirs(pkgRoot, env = process.env) {
|
|
74
|
+
const dirs = [];
|
|
75
|
+
const parentScope = path.dirname(pkgRoot);
|
|
76
|
+
const nodeModulesDir = path.dirname(parentScope);
|
|
77
|
+
if (
|
|
78
|
+
path.basename(parentScope) === '@bitefoundry' &&
|
|
79
|
+
path.basename(nodeModulesDir) === 'node_modules'
|
|
80
|
+
) {
|
|
81
|
+
dirs.push(path.join(nodeModulesDir, '.bin'));
|
|
82
|
+
// On global Windows npm installs (`%APPDATA%\npm\node_modules\@bitefoundry\outlook`),
|
|
83
|
+
// shims sit directly in the parent of `node_modules` even when `npm_config_prefix` is unset in npm v9+.
|
|
84
|
+
dirs.push(path.dirname(nodeModulesDir));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (env.npm_config_global === 'true' && env.npm_config_prefix) {
|
|
88
|
+
const prefix = path.resolve(env.npm_config_prefix);
|
|
89
|
+
dirs.push(prefix);
|
|
90
|
+
dirs.push(path.join(prefix, 'bin'));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [...new Set(dirs)];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function shimReferencesLauncher(content, name) {
|
|
97
|
+
const normalized = content.replace(/\\/g, '/').toLowerCase();
|
|
98
|
+
return (
|
|
99
|
+
normalized.includes('@bitefoundry/outlook') &&
|
|
100
|
+
normalized.includes(`bin/${name}.js`)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function rewriteWindowsShims(shimDir, pkgRoot) {
|
|
105
|
+
if (!fs.existsSync(shimDir)) return 0;
|
|
106
|
+
let rewritten = 0;
|
|
107
|
+
|
|
108
|
+
for (const name of BIN_NAMES) {
|
|
109
|
+
const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
|
|
110
|
+
if (!fs.existsSync(exePath)) continue;
|
|
111
|
+
|
|
112
|
+
const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
|
|
113
|
+
const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
|
|
114
|
+
|
|
115
|
+
// 1. `<name>.cmd`
|
|
116
|
+
const cmdPath = path.join(shimDir, `${name}.cmd`);
|
|
117
|
+
try {
|
|
118
|
+
if (fs.existsSync(cmdPath)) {
|
|
119
|
+
const content = fs.readFileSync(cmdPath, 'utf8');
|
|
120
|
+
if (shimReferencesLauncher(content, name)) {
|
|
121
|
+
fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
|
|
122
|
+
rewritten += 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
// Fall back cleanly to bin/<name>.js if shim is read-only or locked.
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 2. `<name>.ps1`
|
|
130
|
+
const ps1Path = path.join(shimDir, `${name}.ps1`);
|
|
131
|
+
try {
|
|
132
|
+
if (fs.existsSync(ps1Path)) {
|
|
133
|
+
const content = fs.readFileSync(ps1Path, 'utf8');
|
|
134
|
+
if (shimReferencesLauncher(content, name)) {
|
|
135
|
+
const ps1Body = [
|
|
136
|
+
'#!/usr/bin/env pwsh',
|
|
137
|
+
'$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
|
|
138
|
+
`$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
|
|
139
|
+
'if ($MyInvocation.ExpectingInput) {',
|
|
140
|
+
' $input | & $exePath @args',
|
|
141
|
+
'} else {',
|
|
142
|
+
' & $exePath @args',
|
|
143
|
+
'}',
|
|
144
|
+
'exit $LASTEXITCODE',
|
|
145
|
+
'',
|
|
146
|
+
].join('\n');
|
|
147
|
+
fs.writeFileSync(ps1Path, ps1Body, 'utf8');
|
|
148
|
+
rewritten += 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
// Fall back cleanly.
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 3. `<name>` (Git Bash / MSYS2 POSIX shell shim)
|
|
156
|
+
const shPath = path.join(shimDir, name);
|
|
157
|
+
try {
|
|
158
|
+
if (fs.existsSync(shPath)) {
|
|
159
|
+
const content = fs.readFileSync(shPath, 'utf8');
|
|
160
|
+
if (shimReferencesLauncher(content, name)) {
|
|
161
|
+
const shBody = [
|
|
162
|
+
'#!/bin/sh',
|
|
163
|
+
'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
|
|
164
|
+
`exec "$basedir/${relPosix}" "$@"`,
|
|
165
|
+
'',
|
|
166
|
+
].join('\n');
|
|
167
|
+
fs.writeFileSync(shPath, shBody, 'utf8');
|
|
168
|
+
rewritten += 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} catch {
|
|
172
|
+
// Fall back cleanly.
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return rewritten;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function runPostinstall(options = {}) {
|
|
180
|
+
const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
|
|
181
|
+
const platform = options.platform || process.platform;
|
|
182
|
+
const arch = options.arch || process.arch;
|
|
183
|
+
const env = options.env || process.env;
|
|
184
|
+
|
|
185
|
+
// CRITICAL SAFETY GUARD: Never mutate files inside the git development repository.
|
|
186
|
+
if (
|
|
187
|
+
fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
|
|
188
|
+
fs.existsSync(path.join(pkgRoot, '.git'))
|
|
189
|
+
) {
|
|
190
|
+
return { skipped: true, reason: 'dev_repo' };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const platformKey = `${platform}-${arch}`;
|
|
194
|
+
const packageName = `@bitefoundry/outlook-${platformKey}`;
|
|
195
|
+
const binaryName = platform === 'win32' ? 'outlook.exe' : 'outlook';
|
|
196
|
+
|
|
197
|
+
let packageDir = null;
|
|
198
|
+
try {
|
|
199
|
+
const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
|
|
200
|
+
packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
|
|
201
|
+
} catch {
|
|
202
|
+
packageDir = null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
206
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
207
|
+
return { skipped: true, reason: 'missing_platform_binary' };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const binDir = path.join(pkgRoot, 'bin');
|
|
211
|
+
if (!fs.existsSync(binDir)) {
|
|
212
|
+
return { skipped: true, reason: 'missing_bin_dir' };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (platform === 'win32') {
|
|
216
|
+
let linked = 0;
|
|
217
|
+
for (const name of BIN_NAMES) {
|
|
218
|
+
const destExe = path.join(binDir, `${name}.exe`);
|
|
219
|
+
try {
|
|
220
|
+
linkOrCopyFile(binaryPath, destExe);
|
|
221
|
+
linked += 1;
|
|
222
|
+
} catch {
|
|
223
|
+
// Leave fallback JS launcher untouched.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let shimsRewritten = 0;
|
|
228
|
+
for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
|
|
229
|
+
try {
|
|
230
|
+
shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
|
|
231
|
+
} catch {
|
|
232
|
+
// Never fail npm install on read-only or custom shims.
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return { skipped: false, platform, linked, shimsRewritten };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Unix (linux, darwin): chmod once and replace bin/*.js with hardlink/symlink to native binary.
|
|
239
|
+
try {
|
|
240
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
241
|
+
} catch {
|
|
242
|
+
// Ignore on read-only stores.
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let linked = 0;
|
|
246
|
+
for (const name of BIN_NAMES) {
|
|
247
|
+
const destJs = path.join(binDir, `${name}.js`);
|
|
248
|
+
try {
|
|
249
|
+
replaceJsWithNativeLinkUnix(binaryPath, destJs);
|
|
250
|
+
linked += 1;
|
|
251
|
+
} catch {
|
|
252
|
+
// Leave fallback JS launcher intact.
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return { skipped: false, platform, linked };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
260
|
+
try {
|
|
261
|
+
runPostinstall();
|
|
262
|
+
} catch {
|
|
263
|
+
// Postinstall optimization must never fail npm install.
|
|
264
|
+
}
|
|
265
|
+
process.exit(0);
|
|
266
|
+
}
|