nofax 0.2.35 → 0.2.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nofax",
3
- "version": "0.2.35",
3
+ "version": "0.2.37",
4
4
  "mcpName": "io.github.AKzar1el/nofax",
5
5
  "description": "Human-in-the-loop approvals and notifications for AI coding agents via CLI, MCP, and agent hooks.",
6
6
  "type": "module",
@@ -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.35' },
77
+ { name: 'nofax', version: '0.2.37' },
78
78
  { instructions: SERVER_INSTRUCTIONS }
79
79
  );
80
80
 
package/src/mcp-tools.mjs CHANGED
@@ -93,10 +93,17 @@ function publicRequest(request) {
93
93
  return result;
94
94
  }
95
95
 
96
+ function safeSliceEnd(text, end) {
97
+ const previous = text.charCodeAt(end - 1);
98
+ return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
99
+ }
100
+
96
101
  function validateText(value, name, max = 2200) {
97
102
  if (typeof value !== 'string' || !value.trim()) throw new Error(`NOFAX_${name}_REQUIRED`);
98
103
  const text = value.trim();
99
- return text.length <= max ? text : `${text.slice(0, max - 14)}…[truncated]`;
104
+ if (text.length <= max) return text;
105
+ const end = safeSliceEnd(text, max - 14);
106
+ return `${text.slice(0, end)}…[truncated]`;
100
107
  }
101
108
 
102
109
  function validateWaitSeconds(value) {
@@ -124,6 +131,9 @@ function validateChoiceOptions(options) {
124
131
  if (new Set(normalized.map((option) => option.value)).size !== normalized.length) {
125
132
  throw new Error('NOFAX_CHOICE_DUPLICATE');
126
133
  }
134
+ if (new Set(normalized.map((option) => option.label)).size !== normalized.length) {
135
+ throw new Error('NOFAX_CHOICE_DUPLICATE');
136
+ }
127
137
  return normalized;
128
138
  }
129
139
 
@@ -148,13 +158,15 @@ export function createMcpToolHandlers(overrides = {}) {
148
158
  return deps.loadConfigImpl({ home: deps.home, env: deps.env });
149
159
  }
150
160
 
151
- async function persistRemote({ kind, remote }) {
161
+ async function persistRemote({ kind, remote, requestConfig }) {
152
162
  const request = {
153
163
  version: 1,
154
164
  requestId: remote.requestId,
155
165
  kind,
156
166
  responseTopic: remote.responseTopic,
157
167
  allowed: remote.allowed,
168
+ server: requestConfig.server,
169
+ topic: requestConfig.topic,
158
170
  status: 'pending',
159
171
  createdAt: new Date(deps.nowImpl()).toISOString()
160
172
  };
@@ -167,10 +179,10 @@ export function createMcpToolHandlers(overrides = {}) {
167
179
  const remote = await deps.createRemoteRequestImpl({
168
180
  ...input,
169
181
  beforePublish: async (prepared) => {
170
- persisted = await persistRemote({ kind, remote: prepared });
182
+ persisted = await persistRemote({ kind, remote: prepared, requestConfig: input.config });
171
183
  }
172
184
  });
173
- return persisted ?? persistRemote({ kind, remote });
185
+ return persisted ?? persistRemote({ kind, remote, requestConfig: input.config });
174
186
  }
175
187
 
176
188
  return {
@@ -226,7 +238,9 @@ export function createMcpToolHandlers(overrides = {}) {
226
238
  let request = await deps.loadRequestImpl({ home: deps.home, env: deps.env, requestId });
227
239
  if (request.status === 'resolved') return terminalResult(request);
228
240
 
229
- const current = await config();
241
+ const current = request.server && request.topic
242
+ ? { server: request.server, topic: request.topic }
243
+ : await config();
230
244
  const deadline = deps.nowImpl() + seconds * 1000;
231
245
  while (deps.nowImpl() < deadline) {
232
246
  const response = await deps.pollRemoteResponseImpl({
package/src/ntfy.mjs CHANGED
@@ -4,10 +4,17 @@ const MAX_TITLE = 120;
4
4
  const MAX_MESSAGE = 2200;
5
5
  const DEFAULT_REFINE_SHORTCUT = 'Nofax Refine';
6
6
 
7
+ function safeSliceEnd(text, end) {
8
+ const previous = text.charCodeAt(end - 1);
9
+ return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
10
+ }
11
+
7
12
  function boundText(value, max, name) {
8
13
  if (typeof value !== 'string' || value.trim().length === 0) throw new Error(`NOFAX_${name}_REQUIRED`);
9
14
  const text = value.trim();
10
- return text.length <= max ? text : `${text.slice(0, max - 14)}…[truncated]`;
15
+ if (text.length <= max) return text;
16
+ const end = safeSliceEnd(text, max - 14);
17
+ return `${text.slice(0, end)}…[truncated]`;
11
18
  }
12
19
 
13
20
  function sleep(ms) {
@@ -90,6 +97,7 @@ function normalizeOptions(options) {
90
97
  return { value, label: label.slice(0, 32) };
91
98
  });
92
99
  if (new Set(normalized.map((option) => option.value)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
100
+ if (new Set(normalized.map((option) => option.label)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
93
101
  return normalized;
94
102
  }
95
103
 
package/src/protocol.mjs CHANGED
@@ -176,9 +176,15 @@ function randomBase64Url(bytes) {
176
176
  return randomBytes(bytes).toString('base64url');
177
177
  }
178
178
 
179
+ function safeSliceEnd(text, end) {
180
+ const previous = text.charCodeAt(end - 1);
181
+ return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
182
+ }
183
+
179
184
  function boundResponseText(value) {
180
185
  if (value.length <= MAX_RESPONSE_TEXT) return value;
181
- return `${value.slice(0, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length)}${TRUNCATION_MARKER}`;
186
+ const end = safeSliceEnd(value, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length);
187
+ return `${value.slice(0, end)}${TRUNCATION_MARKER}`;
182
188
  }
183
189
 
184
190
  export function createRequestId() {
@@ -195,8 +201,10 @@ export function createPhoneTopic() {
195
201
 
196
202
  function boundString(value) {
197
203
  const redacted = redactSecretText(value);
198
- const bounded = redacted.length <= MAX_STRING ? redacted : redacted.slice(0, MAX_STRING);
199
- return value.length <= MAX_STRING ? bounded : `${bounded}…[truncated]`;
204
+ const bounded = redacted.length <= MAX_STRING
205
+ ? redacted
206
+ : redacted.slice(0, safeSliceEnd(redacted, MAX_STRING));
207
+ return value.length <= MAX_STRING ? bounded : `${bounded}${TRUNCATION_MARKER}`;
200
208
  }
201
209
 
202
210
  export function redactAndBound(value, options = {}) {
@@ -254,7 +262,8 @@ function serializeBounded(value) {
254
262
  serialized = '[unserializable]';
255
263
  }
256
264
  if (serialized.length <= 1400) return serialized;
257
- return `${serialized.slice(0, 1400)}\n…[truncated]`;
265
+ const end = safeSliceEnd(serialized, 1400);
266
+ return `${serialized.slice(0, end)}\n${TRUNCATION_MARKER}`;
258
267
  }
259
268
 
260
269
  export function buildAgentSummary({ source, toolName, cwd, toolInput, message }) {
@@ -266,7 +275,8 @@ export function buildAgentSummary({ source, toolName, cwd, toolInput, message })
266
275
  if (toolInput !== undefined) lines.push('', 'Request:', serializeBounded(toolInput));
267
276
  const result = lines.join('\n').trim();
268
277
  if (result.length <= MAX_SUMMARY) return result;
269
- return `${result.slice(0, MAX_SUMMARY - 14)}\n…[truncated]`;
278
+ const end = safeSliceEnd(result, MAX_SUMMARY - 14);
279
+ return `${result.slice(0, end)}\n${TRUNCATION_MARKER}`;
270
280
  }
271
281
 
272
282
  export function parseResponseMessage(message, { requestId, allowed, kind }) {
package/src/requests.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { chmod, link, mkdir, readFile, readdir, rename, unlink, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import { resolveNofaxHome } from './config.mjs';
3
+ import { normalizeServer, resolveNofaxHome } from './config.mjs';
4
4
 
5
5
  const REQUEST_ID = /^nfx_[A-Za-z0-9_-]{20,80}$/;
6
6
  const RESPONSE_TOPIC = /^nofax_r_[A-Za-z0-9_-]{20,120}$/;
7
+ const PHONE_TOPIC = /^[A-Za-z0-9_-]{24,128}$/;
7
8
  const KINDS = new Set(['approval', 'choice', 'refinement']);
8
9
  const STATUSES = new Set(['pending', 'resolved']);
9
10
  const MAX_RESPONSE_TEXT = 2000;
@@ -14,10 +15,16 @@ function validateRequestId(value) {
14
15
  return value;
15
16
  }
16
17
 
18
+ function safeSliceEnd(text, end) {
19
+ const previous = text.charCodeAt(end - 1);
20
+ return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
21
+ }
22
+
17
23
  function boundResponseText(value) {
18
24
  const text = value.trim();
19
25
  if (text.length <= MAX_RESPONSE_TEXT) return text;
20
- return `${text.slice(0, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length)}${TRUNCATION_MARKER}`;
26
+ const end = safeSliceEnd(text, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length);
27
+ return `${text.slice(0, end)}${TRUNCATION_MARKER}`;
21
28
  }
22
29
 
23
30
  function validateRequest(input) {
@@ -34,6 +41,9 @@ function validateRequest(input) {
34
41
  }
35
42
  if (!STATUSES.has(input.status)) throw new Error('NOFAX_REQUEST_STATUS_INVALID');
36
43
  if (typeof input.createdAt !== 'string' || Number.isNaN(Date.parse(input.createdAt))) throw new Error('NOFAX_REQUEST_CREATED_AT_INVALID');
44
+ const hasServer = input.server !== undefined;
45
+ const hasTopic = input.topic !== undefined;
46
+ if (hasServer !== hasTopic) throw new Error('NOFAX_REQUEST_TRANSPORT_INVALID');
37
47
  const base = {
38
48
  version: 1,
39
49
  requestId,
@@ -43,6 +53,13 @@ function validateRequest(input) {
43
53
  status: input.status,
44
54
  createdAt: input.createdAt
45
55
  };
56
+ if (hasServer) {
57
+ if (typeof input.server !== 'string' || typeof input.topic !== 'string' || !PHONE_TOPIC.test(input.topic)) {
58
+ throw new Error('NOFAX_REQUEST_TRANSPORT_INVALID');
59
+ }
60
+ base.server = normalizeServer(input.server);
61
+ base.topic = input.topic;
62
+ }
46
63
  if (input.status === 'resolved') {
47
64
  if (typeof input.resolvedAt !== 'string' || Number.isNaN(Date.parse(input.resolvedAt))) throw new Error('NOFAX_REQUEST_RESOLVED_AT_INVALID');
48
65
  if (typeof input.decision !== 'string') throw new Error('NOFAX_REQUEST_DECISION_INVALID');