@theronap/agnoclast-mcp 0.9.330 → 0.9.332
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/lib/imessage_send.mjs +28 -8
- package/lib/release_gate.mjs +1 -1
- package/lib/server.mjs +82 -4
- package/lib/work_log_render.mjs +25 -0
- package/package.json +1 -1
package/lib/imessage_send.mjs
CHANGED
|
@@ -19,9 +19,21 @@
|
|
|
19
19
|
//
|
|
20
20
|
// ⚠ THE POST IS NOT IDEMPOTENT. Never retried: a 5xx may mean the request was created.
|
|
21
21
|
|
|
22
|
-
/** PURE. The draft preview
|
|
23
|
-
export function draftText({ recipient, message }) {
|
|
24
|
-
|
|
22
|
+
/** PURE. The draft preview. A reply names the conversation; the server finds the number when it is sent. */
|
|
23
|
+
export function draftText({ recipient, replyTo, message }) {
|
|
24
|
+
const to = replyTo ? `the conversation with ${replyTo} (Agnoclast finds the number when you send)` : recipient
|
|
25
|
+
const again = replyTo ? 'with the same reply_to and send:true' : 'with send:true'
|
|
26
|
+
return `📝 DRAFT (not sent) — to ${to}:\n${message}\n\n(Call send_imessage again ${again} to ask the user to approve it.)`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* PURE. Does `recipient` look like something a text can be addressed to? The server decides for real; this only
|
|
31
|
+
* stops a DRAFT from looking fine for a recipient the send will refuse (2026-11-07: a draft "to Andres" previewed,
|
|
32
|
+
* and the send then said "Andres" is not a phone number). A name belongs in reply_to.
|
|
33
|
+
*/
|
|
34
|
+
export function looksAddressable(recipient) {
|
|
35
|
+
const s = String(recipient ?? '').trim()
|
|
36
|
+
return s.includes('@') || /^\+?[0-9 ().\-]{7,}$/.test(s)
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/**
|
|
@@ -32,6 +44,8 @@ export function draftText({ recipient, message }) {
|
|
|
32
44
|
* Returns { text, isError }.
|
|
33
45
|
*/
|
|
34
46
|
export function textRequestReply(status, body, recipient) {
|
|
47
|
+
// A reply's recipient is the person's name from the server (`recipientName`), never the number.
|
|
48
|
+
if (typeof body?.recipientName === 'string' && body.recipientName) recipient = body.recipientName
|
|
35
49
|
const msg = typeof body?.error === 'string' ? body.error : null
|
|
36
50
|
if (status === 201 || (status >= 200 && status < 300)) {
|
|
37
51
|
const reviewUrl = body?.reviewUrl
|
|
@@ -61,18 +75,24 @@ export function textRequestReply(status, body, recipient) {
|
|
|
61
75
|
* Tool entry. `request` is the injected POST (fetchCortex with retries off, in server.mjs), so this
|
|
62
76
|
* stays testable without a network.
|
|
63
77
|
*/
|
|
64
|
-
export async function runSendImessage({ recipient, message, send }, request) {
|
|
65
|
-
|
|
78
|
+
export async function runSendImessage({ recipient, replyTo, message, send }, request) {
|
|
79
|
+
const hasTo = !!recipient && !!String(recipient).trim()
|
|
80
|
+
const hasReply = !!replyTo && !!String(replyTo).trim()
|
|
81
|
+
if (hasTo && hasReply) return { isError: true, text: 'Give recipient OR reply_to, not both.' }
|
|
82
|
+
if (!hasTo && !hasReply) return { isError: true, text: 'Name who to text: a phone number or iMessage email in recipient, or — to answer a text — the person\'s name or their text\'s id in reply_to.' }
|
|
83
|
+
if (hasTo && !looksAddressable(recipient)) {
|
|
84
|
+
return { isError: true, text: `"${String(recipient).trim().slice(0, 80)}" is not a phone number or iMessage email. To answer someone who texted the user, pass their name as reply_to instead; otherwise ask the user for the number.` }
|
|
85
|
+
}
|
|
66
86
|
if (!message || !String(message).trim()) return { isError: true, text: 'The text is empty.' }
|
|
67
|
-
if (send !== true) return { isError: false, text: draftText({ recipient, message }) }
|
|
87
|
+
if (send !== true) return { isError: false, text: draftText({ recipient, replyTo: hasReply ? String(replyTo).trim() : undefined, message }) }
|
|
68
88
|
let res
|
|
69
89
|
try {
|
|
70
|
-
res = await request({ to: String(recipient).trim(), text: String(message) })
|
|
90
|
+
res = await request(hasReply ? { replyTo: String(replyTo).trim(), text: String(message) } : { to: String(recipient).trim(), text: String(message) })
|
|
71
91
|
} catch (e) {
|
|
72
92
|
return { isError: true, text:
|
|
73
93
|
`Could not confirm the text request: ${e?.message ?? e} ⚠ It may have been created anyway. ` +
|
|
74
94
|
`Do NOT call send_imessage again — ask the user to check Email in Agnoclast.` }
|
|
75
95
|
}
|
|
76
96
|
const body = await res.json().catch(() => null)
|
|
77
|
-
return textRequestReply(res.status, body, recipient)
|
|
97
|
+
return textRequestReply(res.status, body, hasReply ? String(replyTo).trim() : recipient)
|
|
78
98
|
}
|
package/lib/release_gate.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// That is safe because hiding a tool is a courtesy, and every gated route checks its own flag on the server.
|
|
12
12
|
|
|
13
13
|
/** Tools any release flag gates — hidden when the server cannot be asked. Mirror of allGatedTools(). */
|
|
14
|
-
export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'file_document', 'find_documents', 'finish_task', 'get_document', 'hand_task', 'handed_tasks', 'hold_task', 'import_document_as_page', 'intake_shadow', 'list_documents', 'merge_pages', 'my_messages', 'my_tasks', 'pin_document', 'place_split_records', 'read_conversation', 'read_document', 'relink_links', 'send_message', 'set_manager', 'set_working_hours', 'split_page', 'split_records', 'store_file', 'tasks_waiting', 'undo_merge', 'undo_relink', 'undo_split', 'upload_document_version']
|
|
14
|
+
export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'file_document', 'find_documents', 'finish_task', 'get_document', 'hand_task', 'handed_tasks', 'hold_task', 'import_document_as_page', 'intake_shadow', 'list_documents', 'log_work', 'merge_pages', 'my_messages', 'my_tasks', 'pin_document', 'place_split_records', 'read_conversation', 'read_document', 'relink_links', 'send_message', 'set_manager', 'set_working_hours', 'split_page', 'split_records', 'store_file', 'tasks_waiting', 'undo_merge', 'undo_relink', 'undo_split', 'upload_document_version', 'work_log']
|
|
15
15
|
|
|
16
16
|
export const RELEASE_FETCH_TIMEOUT_MS = 2500
|
|
17
17
|
/** A remembered answer older than this is not trusted: a week covers a quiet weekend without hiding tools for long. */
|
package/lib/server.mjs
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
UPDATE_EVENT_DESCRIPTION, UPDATE_SERIES_DESCRIPTION, renderEventCancelled, renderSeriesRevised, seriesPatchBody,
|
|
48
48
|
} from './calendar_events.mjs'
|
|
49
49
|
import { formatFoundDocuments } from './found_documents.mjs'
|
|
50
|
+
import { renderWorkLog } from './work_log_render.mjs'
|
|
50
51
|
import { fileSealedCapture } from './file_sealed_capture.mjs'
|
|
51
52
|
|
|
52
53
|
// PAGE tiers (ADR-0071). Six for a PAGE; a RECORD keeps three (`privacy` on log_session and
|
|
@@ -509,6 +510,28 @@ export async function runServer(version) {
|
|
|
509
510
|
return lines.length ? lines.join('\n') : null
|
|
510
511
|
} catch { return null }
|
|
511
512
|
}
|
|
513
|
+
// The daily work log (web/lib/engine/agent_work_log.ts; design page "Upkeep without Claude Code (design)" v3):
|
|
514
|
+
// changes this agent made that no log_work line covers, once they have waited. The server decides and throttles
|
|
515
|
+
// (one nudge per agent per window); here we only ask, on a process's first result and then at most every five
|
|
516
|
+
// minutes. Not inside Claude Code, whose hooks and close-out already log its sessions.
|
|
517
|
+
let workLogLookedAt = 0
|
|
518
|
+
const workLogNudge = async (name) => {
|
|
519
|
+
if (process.env.CLAUDE_CODE_SESSION_ID || name === 'log_work' || name === 'work_log') return null
|
|
520
|
+
const now = Date.now()
|
|
521
|
+
if (workLogLookedAt && now - workLogLookedAt < 300_000) return null
|
|
522
|
+
workLogLookedAt = now
|
|
523
|
+
try {
|
|
524
|
+
if (!toolHandles.has('log_work')) return null // behind a release flag this caller's brains lack
|
|
525
|
+
const res = await Promise.race([
|
|
526
|
+
fetchCortex(`${BASE}/api/me/work-log?nudge=1`, { headers: { Authorization: `Bearer ${TOKEN}` } }),
|
|
527
|
+
new Promise((resolve) => setTimeout(resolve, 2000, null).unref()),
|
|
528
|
+
])
|
|
529
|
+
if (!res) return null
|
|
530
|
+
if (!res.ok) { try { await res.body?.cancel() } catch { /* nothing to drain */ } return null }
|
|
531
|
+
const { nudge } = await res.json()
|
|
532
|
+
return typeof nudge === 'string' && nudge ? nudge : null
|
|
533
|
+
} catch { return null }
|
|
534
|
+
}
|
|
512
535
|
// ADR-0070: every tool runs with its NAME in async context, so an outage fetchCortex auto-files is
|
|
513
536
|
// attributed to the tool that hit it rather than guessed from a URL shared by several tools.
|
|
514
537
|
const registerTool = server.registerTool.bind(server)
|
|
@@ -547,6 +570,8 @@ export async function runServer(version) {
|
|
|
547
570
|
const result = await handler(...args)
|
|
548
571
|
const taskLine = name === 'my_tasks' || name === 'handed_tasks' || name === 'tasks_waiting' ? null : await taskNotice()
|
|
549
572
|
if (taskLine && Array.isArray(result?.content)) result.content = [...result.content, { type: 'text', text: taskLine }]
|
|
573
|
+
const workLine = result?.isError ? null : await workLogNudge(name)
|
|
574
|
+
if (workLine && Array.isArray(result?.content)) result.content = [...result.content, { type: 'text', text: workLine }]
|
|
550
575
|
if (!result?.isError) {
|
|
551
576
|
if (name === 'log_session') {
|
|
552
577
|
if (result?.content?.[0]?.text?.startsWith('Logged')) noteLogged(rolling, takesArgs ? args[0]?.summary : null)
|
|
@@ -6555,6 +6580,58 @@ function renderNudge(payload) {
|
|
|
6555
6580
|
},
|
|
6556
6581
|
)
|
|
6557
6582
|
|
|
6583
|
+
server.registerTool(
|
|
6584
|
+
'log_work',
|
|
6585
|
+
{
|
|
6586
|
+
title: 'Add a line to my work log',
|
|
6587
|
+
description: 'Add ONE short line to YOUR daily work log saying what you just did and why, right after you do it, e.g. "answered 38 routine refund emails from the FAQ page" or "escalated the Ortiz insurance claim to Theron; updated Refund log". One line may cover many actions, so write it at each natural stopping point, not per call. Name the wiki pages you changed in `pages`. A summary of the work, never a transcript of the conversation. Agnoclast shows the changes you have made that no line covers yet, in work_log and as a note on your results.',
|
|
6588
|
+
inputSchema: {
|
|
6589
|
+
line: z.string().describe('what you did and why, in one sentence'),
|
|
6590
|
+
pages: z.array(z.string()).optional().describe('titles of the wiki pages this work changed'),
|
|
6591
|
+
asked: z.string().optional().describe('what the person asked for, in a few words, if this came from a request'),
|
|
6592
|
+
},
|
|
6593
|
+
},
|
|
6594
|
+
async ({ line, pages, asked }) => {
|
|
6595
|
+
let res
|
|
6596
|
+
try {
|
|
6597
|
+
res = await fetchCortex(`${BASE}/api/me/work-log`, {
|
|
6598
|
+
method: 'POST',
|
|
6599
|
+
headers: { Authorization: `Bearer ${TOKEN}`, 'content-type': 'application/json' },
|
|
6600
|
+
body: JSON.stringify({ line, pages, asked }),
|
|
6601
|
+
})
|
|
6602
|
+
} catch (e) {
|
|
6603
|
+
return toolError(`Could not add to your work log: ${e.message}`)
|
|
6604
|
+
}
|
|
6605
|
+
if (res.status === 400) return toolError('log_work needs a non-empty `line`, and an agent token (console sessions have none).')
|
|
6606
|
+
if (!res.ok) {
|
|
6607
|
+
const d = classify(res.status, res.headers.get('content-type'), await res.text(), res.headers.get('x-vercel-id'))
|
|
6608
|
+
return toolError(`Could not add to your work log: ${d.message}`)
|
|
6609
|
+
}
|
|
6610
|
+
return { content: [{ type: 'text', text: 'Added to your work log for today.' }] }
|
|
6611
|
+
},
|
|
6612
|
+
)
|
|
6613
|
+
|
|
6614
|
+
server.registerTool(
|
|
6615
|
+
'work_log',
|
|
6616
|
+
{
|
|
6617
|
+
title: 'My work log today',
|
|
6618
|
+
description: 'Read YOUR OWN work log for today: the lines you wrote with log_work, then the changes you made (page edits, filings, discards) that no line covers yet. Use it to answer "what have you done today?", or before you stop, to cover anything left with one log_work line.',
|
|
6619
|
+
},
|
|
6620
|
+
async () => {
|
|
6621
|
+
let res
|
|
6622
|
+
try {
|
|
6623
|
+
res = await fetchCortex(`${BASE}/api/me/work-log`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
6624
|
+
} catch (e) {
|
|
6625
|
+
return toolError(`Could not read your work log: ${e.message}`)
|
|
6626
|
+
}
|
|
6627
|
+
if (!res.ok) {
|
|
6628
|
+
const d = classify(res.status, res.headers.get('content-type'), await res.text(), res.headers.get('x-vercel-id'))
|
|
6629
|
+
return toolError(`Could not read your work log: ${d.message}`)
|
|
6630
|
+
}
|
|
6631
|
+
return { content: [{ type: 'text', text: renderWorkLog(await res.json()) }] }
|
|
6632
|
+
},
|
|
6633
|
+
)
|
|
6634
|
+
|
|
6558
6635
|
server.registerTool(
|
|
6559
6636
|
'token_activity',
|
|
6560
6637
|
{
|
|
@@ -8333,16 +8410,17 @@ function renderNudge(payload) {
|
|
|
8333
8410
|
'send_imessage',
|
|
8334
8411
|
{
|
|
8335
8412
|
title: 'Ask to send a text (iMessage) from the user\'s Mac',
|
|
8336
|
-
description: 'Text someone from the USER\'S OWN Mac, through Messages. Without send:true this only returns a draft preview. With send:true it creates a request that WAITS for the user to approve it
|
|
8413
|
+
description: 'Text someone from the USER\'S OWN Mac, through Messages. To answer a text they got, pass reply_to (the person\'s name, or the id of their text) instead of recipient: Agnoclast finds the number, which you never need. Without send:true this only returns a draft preview. With send:true it creates a request that WAITS for the user to approve it (their phone is notified), unless their own send rule allows it; once approved, their Mac sends it within about a minute. The text is frozen when the request is made, so write the final wording, and show the user what you are about to send first. ⚠ NEVER call it twice with send:true for the same text — it is not idempotent.',
|
|
8337
8414
|
inputSchema: {
|
|
8338
|
-
recipient: z.string().describe('one phone number (e.g. +18015551234, or (801) 555-1234 for a US number) or iMessage email address'),
|
|
8415
|
+
recipient: z.string().optional().describe('one phone number (e.g. +18015551234, or (801) 555-1234 for a US number) or iMessage email address. Omit when using reply_to'),
|
|
8416
|
+
reply_to: z.string().optional().describe('instead of recipient: the conversation to answer — the person\'s name as their texts show it (e.g. "Zach Nielsen"), or the id of a captured text from them'),
|
|
8339
8417
|
message: z.string().describe('the text to send'),
|
|
8340
8418
|
send: z.boolean().optional().describe('true to ask the user to approve sending it; omit or false for a draft preview only'),
|
|
8341
8419
|
confirm: z.string().optional().describe('NO LONGER USED — approval happens in Agnoclast now. Ignored.'),
|
|
8342
8420
|
},
|
|
8343
8421
|
},
|
|
8344
|
-
async ({ recipient, message, send }) => {
|
|
8345
|
-
const r = await runSendImessage({ recipient, message, send }, (body) => fetchCortex(`${BASE}/api/texts/send-requests`, {
|
|
8422
|
+
async ({ recipient, reply_to, message, send }) => {
|
|
8423
|
+
const r = await runSendImessage({ recipient, replyTo: reply_to, message, send }, (body) => fetchCortex(`${BASE}/api/texts/send-requests`, {
|
|
8346
8424
|
method: 'POST',
|
|
8347
8425
|
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
8348
8426
|
body: JSON.stringify(body),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Renders GET /api/me/work-log for the `work_log` tool. Mirrors renderWorkLog in web/lib/engine/agent_work_log.ts
|
|
2
|
+
// (the hosted connector's copy), which this package cannot import.
|
|
3
|
+
const TZ = 'America/Denver'
|
|
4
|
+
const KIND_WORD = { edit: 'edited', placement: 'filed', discard: 'discarded an arrival from' }
|
|
5
|
+
|
|
6
|
+
const time = (iso) => new Date(iso).toLocaleTimeString('en-US', { timeZone: TZ, hour: 'numeric', minute: '2-digit' })
|
|
7
|
+
const stub = (a) => `${KIND_WORD[a.kind] ?? a.kind} ${a.what ? `"${a.what}"` : 'an item'}${a.reason ? ` (${a.reason})` : ''}`
|
|
8
|
+
|
|
9
|
+
export function renderWorkLog(log) {
|
|
10
|
+
const who = log?.agent?.label ?? 'this connection'
|
|
11
|
+
const lines = log?.lines ?? []
|
|
12
|
+
const uncovered = log?.uncovered ?? []
|
|
13
|
+
const out = [
|
|
14
|
+
`Work log for ${who}, ${log?.day ?? 'today'} (${TZ}):`,
|
|
15
|
+
lines.length
|
|
16
|
+
? lines.map((l) => `- ${time(l.at)} ${l.line}${l.pages?.length ? ` [pages: ${l.pages.join(', ')}]` : ''}`).join('\n')
|
|
17
|
+
: '(no lines yet today)',
|
|
18
|
+
]
|
|
19
|
+
if (uncovered.length) {
|
|
20
|
+
out.push('', `Not yet covered by a line (${uncovered.length}):`,
|
|
21
|
+
...uncovered.slice(0, 20).map((a) => `- ${time(a.at)} ${stub(a)}`),
|
|
22
|
+
'Cover them with log_work.')
|
|
23
|
+
}
|
|
24
|
+
return out.join('\n')
|
|
25
|
+
}
|
package/package.json
CHANGED