nofax 0.2.39 → 0.2.41
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/CHANGELOG.md +18 -0
- package/package.json +1 -1
- package/src/cli.mjs +16 -5
- package/src/mcp-server.mjs +1 -1
- package/src/mcp-tools.mjs +19 -6
- package/src/ntfy.mjs +20 -4
- package/src/requests.mjs +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -42,6 +42,24 @@ Local Nofax `0.2.x` behavior is unchanged by these removals.
|
|
|
42
42
|
- The capability-path form is normalized to `/mcp` before MCP protocol handling.
|
|
43
43
|
- Remote read operations perform no external messaging/provider calls; only explicit `nofax_notify` invokes ntfy.
|
|
44
44
|
|
|
45
|
+
## 0.2.41 - 2026-09-24
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- Durable MCP requests created before ntfy publication are now removed only when ntfy authoritatively rejects that publish with a validation or rate-limit response; network and other delivery-ambiguous failures keep the pending record for safe recovery, and an already-terminal human response is never discarded.
|
|
50
|
+
- Human-visible choice labels now preserve valid UTF-16 at the existing 32-code-unit ntfy action-label boundary, so an astral Unicode character is never split into an unpaired surrogate while the full decision value and duplicate-label safeguards remain unchanged.
|
|
51
|
+
|
|
52
|
+
Pending, timeout, disconnect, setup/config failure, ambiguous transport failure, and notification delivery still never mean approval. Explicit Allow/Deny behavior, response-topic secrecy, first-terminal-wins semantics, notification authority, and the narrower remote Worker boundary are unchanged.
|
|
53
|
+
|
|
54
|
+
## 0.2.40 - 2026-09-24
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- CLI commands now reject recognized flags that the selected command does not support before loading configuration or performing any notification/approval side effect, preventing ignored routing or timing flags from making a malformed invocation look valid.
|
|
59
|
+
- Commands that do not accept positional input now reject unexpected trailing arguments before configuration loading, transport, MCP startup, or hook approval work, while message-bearing commands keep their documented positional behavior.
|
|
60
|
+
|
|
61
|
+
Pending, timeout, disconnect, setup/config failure, transport failure, and notification delivery still never mean approval. Explicit Allow/Deny behavior, response-topic secrecy, first-terminal-wins semantics, notification authority, and the narrower remote Worker boundary are unchanged.
|
|
62
|
+
|
|
45
63
|
## 0.2.39 - 2026-09-24
|
|
46
64
|
|
|
47
65
|
### Changed
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -17,16 +17,18 @@ async function readPackageVersion() {
|
|
|
17
17
|
return metadata.version;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function parseArgs(args) {
|
|
20
|
+
function parseArgs(args, allowedFlags = []) {
|
|
21
21
|
const flags = {};
|
|
22
22
|
const positionals = [];
|
|
23
23
|
for (let index = 0; index < args.length; index += 1) {
|
|
24
24
|
const value = args[index];
|
|
25
25
|
if (value === '--force') {
|
|
26
|
+
if (!allowedFlags.includes(value)) throw new Error(`NOFAX_UNKNOWN_FLAG:${value}`);
|
|
26
27
|
flags.force = true;
|
|
27
28
|
continue;
|
|
28
29
|
}
|
|
29
30
|
if (['--title', '--server', '--topic', '--timeout'].includes(value)) {
|
|
31
|
+
if (!allowedFlags.includes(value)) throw new Error(`NOFAX_UNKNOWN_FLAG:${value}`);
|
|
30
32
|
const next = args[index + 1];
|
|
31
33
|
if (next === undefined) throw new Error(`NOFAX_FLAG_VALUE:${value}`);
|
|
32
34
|
flags[value.slice(2)] = next;
|
|
@@ -39,6 +41,10 @@ function parseArgs(args) {
|
|
|
39
41
|
return { flags, positionals };
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
function rejectUnexpectedArgs(positionals) {
|
|
45
|
+
if (positionals.length > 0) throw new Error(`NOFAX_UNEXPECTED_ARGUMENT:${positionals[0]}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
async function readStdin(stdinText) {
|
|
43
49
|
if (stdinText !== undefined) return stdinText;
|
|
44
50
|
let text = '';
|
|
@@ -124,7 +130,8 @@ export async function runCli(args, overrides = {}) {
|
|
|
124
130
|
|
|
125
131
|
const command = args[0];
|
|
126
132
|
if (command === 'init') {
|
|
127
|
-
const { flags } = parseArgs(args.slice(1));
|
|
133
|
+
const { flags, positionals } = parseArgs(args.slice(1), ['--server', '--topic', '--timeout', '--force']);
|
|
134
|
+
rejectUnexpectedArgs(positionals);
|
|
128
135
|
const timeoutSeconds = flags.timeout === undefined ? undefined : Number(flags.timeout);
|
|
129
136
|
const config = await deps.initConfigImpl({
|
|
130
137
|
env: deps.env,
|
|
@@ -140,12 +147,14 @@ export async function runCli(args, overrides = {}) {
|
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
if (command === 'config') {
|
|
150
|
+
rejectUnexpectedArgs(args.slice(1));
|
|
143
151
|
const config = await deps.loadConfigImpl({ env: deps.env });
|
|
144
152
|
deps.stdout.write(`${JSON.stringify(config, null, 2)}\n`);
|
|
145
153
|
return 0;
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
if (command === 'test') {
|
|
157
|
+
rejectUnexpectedArgs(args.slice(1));
|
|
149
158
|
const config = await deps.loadConfigImpl({ env: deps.env });
|
|
150
159
|
await deps.sendNotificationImpl({
|
|
151
160
|
config,
|
|
@@ -157,7 +166,7 @@ export async function runCli(args, overrides = {}) {
|
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
if (command === 'notify') {
|
|
160
|
-
const { flags, positionals } = parseArgs(args.slice(1));
|
|
169
|
+
const { flags, positionals } = parseArgs(args.slice(1), ['--title']);
|
|
161
170
|
if (positionals.length === 0) throw new Error('NOFAX_MESSAGE_REQUIRED');
|
|
162
171
|
const config = await deps.loadConfigImpl({ env: deps.env });
|
|
163
172
|
await deps.sendNotificationImpl({
|
|
@@ -170,7 +179,7 @@ export async function runCli(args, overrides = {}) {
|
|
|
170
179
|
}
|
|
171
180
|
|
|
172
181
|
if (command === 'approve') {
|
|
173
|
-
const { flags, positionals } = parseArgs(args.slice(1));
|
|
182
|
+
const { flags, positionals } = parseArgs(args.slice(1), ['--title']);
|
|
174
183
|
if (positionals.length === 0) throw new Error('NOFAX_MESSAGE_REQUIRED');
|
|
175
184
|
const config = await deps.loadConfigImpl({ env: deps.env });
|
|
176
185
|
const result = await deps.requestApprovalImpl({
|
|
@@ -183,7 +192,7 @@ export async function runCli(args, overrides = {}) {
|
|
|
183
192
|
}
|
|
184
193
|
|
|
185
194
|
if (command === 'refine') {
|
|
186
|
-
const { flags, positionals } = parseArgs(args.slice(1));
|
|
195
|
+
const { flags, positionals } = parseArgs(args.slice(1), ['--title']);
|
|
187
196
|
if (positionals.length === 0) throw new Error('NOFAX_MESSAGE_REQUIRED');
|
|
188
197
|
const config = await deps.loadConfigImpl({ env: deps.env });
|
|
189
198
|
const result = await deps.requestRefinementImpl({
|
|
@@ -199,6 +208,7 @@ export async function runCli(args, overrides = {}) {
|
|
|
199
208
|
}
|
|
200
209
|
|
|
201
210
|
if (command === 'mcp') {
|
|
211
|
+
rejectUnexpectedArgs(args.slice(1));
|
|
202
212
|
await deps.runMcpServerImpl();
|
|
203
213
|
return 0;
|
|
204
214
|
}
|
|
@@ -206,6 +216,7 @@ export async function runCli(args, overrides = {}) {
|
|
|
206
216
|
if (command === 'hook') {
|
|
207
217
|
const adapter = args[1];
|
|
208
218
|
if (!adapter) throw new Error('NOFAX_HOOK_REQUIRED');
|
|
219
|
+
rejectUnexpectedArgs(args.slice(2));
|
|
209
220
|
try {
|
|
210
221
|
return await runHook(adapter, deps);
|
|
211
222
|
} catch (error) {
|
package/src/mcp-server.mjs
CHANGED
|
@@ -74,7 +74,7 @@ const LIST_PENDING_OUTPUT_SCHEMA = z.object({
|
|
|
74
74
|
|
|
75
75
|
export function buildMcpServer({ handlers = createMcpToolHandlers() } = {}) {
|
|
76
76
|
const server = new McpServer(
|
|
77
|
-
{ name: 'nofax', version: '0.2.
|
|
77
|
+
{ name: 'nofax', version: '0.2.41' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
sendResponseConfirmation
|
|
7
7
|
} from './ntfy.mjs';
|
|
8
8
|
import {
|
|
9
|
+
discardPendingRequest,
|
|
9
10
|
listPendingRequests,
|
|
10
11
|
loadRequest,
|
|
11
12
|
resolveRequestWithClaim,
|
|
@@ -146,6 +147,7 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
146
147
|
createRemoteRequestImpl: overrides.createRemoteRequestImpl ?? createRemoteRequest,
|
|
147
148
|
pollRemoteResponseImpl: overrides.pollRemoteResponseImpl ?? pollRemoteResponse,
|
|
148
149
|
sendResponseConfirmationImpl: overrides.sendResponseConfirmationImpl ?? sendResponseConfirmation,
|
|
150
|
+
discardPendingRequestImpl: overrides.discardPendingRequestImpl ?? discardPendingRequest,
|
|
149
151
|
savePendingRequestImpl: overrides.savePendingRequestImpl ?? savePendingRequest,
|
|
150
152
|
loadRequestImpl: overrides.loadRequestImpl ?? loadRequest,
|
|
151
153
|
resolveRequestWithClaimImpl: overrides.resolveRequestWithClaimImpl ?? resolveRequestWithClaim,
|
|
@@ -176,13 +178,24 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
176
178
|
|
|
177
179
|
async function createDurableRemote(kind, input) {
|
|
178
180
|
let persisted;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
try {
|
|
182
|
+
const remote = await deps.createRemoteRequestImpl({
|
|
183
|
+
...input,
|
|
184
|
+
beforePublish: async (prepared) => {
|
|
185
|
+
persisted = await persistRemote({ kind, remote: prepared, requestConfig: input.config });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return persisted ?? persistRemote({ kind, remote, requestConfig: input.config });
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (persisted && error?.deliveryState === 'not_applied') {
|
|
191
|
+
try {
|
|
192
|
+
await deps.discardPendingRequestImpl({ home: deps.home, env: deps.env, requestId: persisted.requestId });
|
|
193
|
+
} catch (cleanupError) {
|
|
194
|
+
error.cleanupError = cleanupError;
|
|
195
|
+
}
|
|
183
196
|
}
|
|
184
|
-
|
|
185
|
-
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
186
199
|
}
|
|
187
200
|
|
|
188
201
|
return {
|
package/src/ntfy.mjs
CHANGED
|
@@ -3,12 +3,18 @@ import { createRequestId, createResponseTopic, parseResponseMessage } from './pr
|
|
|
3
3
|
const MAX_TITLE = 120;
|
|
4
4
|
const MAX_MESSAGE = 2200;
|
|
5
5
|
const DEFAULT_REFINE_SHORTCUT = 'Nofax Refine';
|
|
6
|
+
// ntfy rejects validation and rate-limit responses before accepting the publish.
|
|
7
|
+
const NOT_APPLIED_PUBLISH_STATUSES = new Set([400, 429]);
|
|
6
8
|
|
|
7
9
|
function safeSliceEnd(text, end) {
|
|
8
10
|
const previous = text.charCodeAt(end - 1);
|
|
9
11
|
return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
function boundChoiceLabel(value) {
|
|
15
|
+
return value.slice(0, safeSliceEnd(value, 32));
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
function boundText(value, max, name) {
|
|
13
19
|
if (typeof value !== 'string' || value.trim().length === 0) throw new Error(`NOFAX_${name}_REQUIRED`);
|
|
14
20
|
const text = value.trim();
|
|
@@ -59,6 +65,12 @@ async function ensureOk(response, code) {
|
|
|
59
65
|
return response;
|
|
60
66
|
}
|
|
61
67
|
|
|
68
|
+
function publishError(message, deliveryState) {
|
|
69
|
+
const error = new Error(message);
|
|
70
|
+
error.deliveryState = deliveryState;
|
|
71
|
+
return error;
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
export async function sendNotification({ config, title, message, actions, priority = 4, tags = ['bell'], fetchImpl = fetch }) {
|
|
63
75
|
const payload = {
|
|
64
76
|
topic: config.topic,
|
|
@@ -77,9 +89,13 @@ export async function sendNotification({ config, title, message, actions, priori
|
|
|
77
89
|
body: JSON.stringify(payload)
|
|
78
90
|
});
|
|
79
91
|
} catch (error) {
|
|
80
|
-
throw
|
|
92
|
+
throw publishError(`NOFAX_NTFY_PUBLISH_NETWORK: ${error?.message ?? String(error)}`, 'ambiguous');
|
|
93
|
+
}
|
|
94
|
+
if (!response?.ok) {
|
|
95
|
+
const status = response?.status ?? 'NETWORK';
|
|
96
|
+
const deliveryState = NOT_APPLIED_PUBLISH_STATUSES.has(status) ? 'not_applied' : 'ambiguous';
|
|
97
|
+
throw publishError(`NOFAX_NTFY_PUBLISH_${status}`, deliveryState);
|
|
81
98
|
}
|
|
82
|
-
await ensureOk(response, 'NOFAX_NTFY_PUBLISH');
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
function normalizeOptions(options) {
|
|
@@ -88,13 +104,13 @@ function normalizeOptions(options) {
|
|
|
88
104
|
if (typeof option === 'string') {
|
|
89
105
|
const value = option.trim();
|
|
90
106
|
if (!value || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
91
|
-
return { value, label: value
|
|
107
|
+
return { value, label: boundChoiceLabel(value) };
|
|
92
108
|
}
|
|
93
109
|
if (!option || typeof option.value !== 'string' || typeof option.label !== 'string') throw new Error('NOFAX_CHOICE_INVALID');
|
|
94
110
|
const value = option.value.trim();
|
|
95
111
|
const label = option.label.trim();
|
|
96
112
|
if (!value || !label || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
97
|
-
return { value, label: label
|
|
113
|
+
return { value, label: boundChoiceLabel(label) };
|
|
98
114
|
});
|
|
99
115
|
if (new Set(normalized.map((option) => option.value)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
100
116
|
if (new Set(normalized.map((option) => option.label)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
|
package/src/requests.mjs
CHANGED
|
@@ -135,6 +135,21 @@ export async function savePendingRequest({ home, env, request }) {
|
|
|
135
135
|
return normalized;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
export async function discardPendingRequest({ home, env, requestId }) {
|
|
139
|
+
const { file, terminal } = paths({ home, env, requestId });
|
|
140
|
+
if (await loadTerminalClaim(terminal) !== null) return false;
|
|
141
|
+
try {
|
|
142
|
+
const current = validateRequest(JSON.parse(await readFile(file, 'utf8')));
|
|
143
|
+
if (current.status !== 'pending') return false;
|
|
144
|
+
await unlink(file);
|
|
145
|
+
return true;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error?.code === 'ENOENT') return false;
|
|
148
|
+
if (error instanceof SyntaxError) throw new Error('NOFAX_REQUEST_INVALID_JSON');
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
export async function loadRequest({ home, env, requestId }) {
|
|
139
154
|
const { file, terminal } = paths({ home, env, requestId });
|
|
140
155
|
const claimed = await loadTerminalClaim(terminal);
|