@theronap/agnoclast-mcp 0.9.211 → 0.9.212
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/diagnose.mjs +3 -1
- package/lib/folder_decisions.mjs +80 -0
- package/lib/identifier_routes.mjs +4 -0
- package/lib/server.mjs +40 -7
- package/package.json +1 -1
package/lib/diagnose.mjs
CHANGED
|
@@ -414,7 +414,9 @@ async function fetchCortexOnce(url, opts = {}, policy = {}) {
|
|
|
414
414
|
sleep: sleepFn = sleep, random = Math.random, now = Date.now,
|
|
415
415
|
} = policy
|
|
416
416
|
const { timeoutMs: optTimeout, signal: callerSignal, ...rest } = opts
|
|
417
|
-
|
|
417
|
+
// x-cortex-tool: the tool this request is for (the running one, else the path map) — the server
|
|
418
|
+
// counts calls per tool for staff usage stats (api_requests). A name only; arguments never travel.
|
|
419
|
+
const baseHeaders = { ...(rest.headers ?? {}), 'x-cortex-client': CLIENT_ID, 'x-cortex-tool': toolForUrl(url) }
|
|
418
420
|
const fetchOpts = SESSION_KEY
|
|
419
421
|
? { ...rest, headers: { ...baseHeaders, 'x-cortex-session-key': SESSION_KEY } }
|
|
420
422
|
: { ...rest, headers: baseHeaders }
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// THE FORCED FOLDER QUESTION AND THE DECLINE LIST — pure renderers (ADR-0077, 2026-10-05).
|
|
2
|
+
//
|
|
3
|
+
// The server refuses to file a GitHub unit until every changed path has an answer. The refusal is only
|
|
4
|
+
// useful if the judge can answer it in ONE more call, so this prints every open question with what it
|
|
5
|
+
// accepts, the candidate pages (and their tiers), any earlier decision being re-asked, and a
|
|
6
|
+
// ready-to-edit `folderDecisions` value. Pure so CI can execute exactly what each refusal prints.
|
|
7
|
+
|
|
8
|
+
const q = (s) => `"${s}"`
|
|
9
|
+
|
|
10
|
+
/** The refusal text for a 409/400/403 from intake_materialize carrying ADR-0077 questions. */
|
|
11
|
+
export function renderFolderQuestions(body) {
|
|
12
|
+
const lines = []
|
|
13
|
+
const questions = Array.isArray(body?.questions) ? body.questions : []
|
|
14
|
+
const pages = Array.isArray(body?.candidatePages) ? body.candidatePages : []
|
|
15
|
+
const head = {
|
|
16
|
+
folder_decisions_required: 'Not filed yet — these paths have no page and no decision. Answer each, then call again with folderDecisions.',
|
|
17
|
+
claim_tier_unconfirmed: 'Not filed yet — that page is narrower than accessible.',
|
|
18
|
+
folder_defer_not_allowed: 'Not filed yet — only a cold judge may defer.',
|
|
19
|
+
decline_never_needs_working_session: 'Not filed yet — a cold judge may not decline "never".',
|
|
20
|
+
folder_decision_unmatched: 'Not filed yet — an answer matched no open question.',
|
|
21
|
+
folder_claim_on_mother_page: 'Not filed yet — that is the repo\'s mother page.',
|
|
22
|
+
folder_claim_not_a_project_page: 'Not filed yet — code belongs on a project page.',
|
|
23
|
+
folder_claim_page_unresolved: 'Not filed yet — that page could not be resolved.',
|
|
24
|
+
}[body?.error] ?? `Not filed yet — ${body?.error ?? 'folder decision refused'}.`
|
|
25
|
+
lines.push(head)
|
|
26
|
+
if (typeof body?.detail === 'string') lines.push(body.detail)
|
|
27
|
+
if (body?.page?.tier) lines.push(`Page: ${q(body.page.title)} (${body.page.tier}) — ref ${body.page.ref}`)
|
|
28
|
+
const open = questions.filter((x) => !x.answered)
|
|
29
|
+
if (open.length) {
|
|
30
|
+
lines.push('', `Open (${open.length}):`)
|
|
31
|
+
for (const x of open) {
|
|
32
|
+
const what = x.kind === 'file' ? `file in grab-bag \`${x.grabBag ?? '?'}\`` : `folder (${x.files?.length ?? 0} changed file${x.files?.length === 1 ? '' : 's'})`
|
|
33
|
+
lines.push(`- \`${x.identifier}\` — ${what}`)
|
|
34
|
+
if (Array.isArray(x.answerWith) && x.answerWith.length > 1) {
|
|
35
|
+
lines.push(` may also be answered at: ${x.answerWith.slice(1).map((a) => `\`${a}\``).join(', ')}`)
|
|
36
|
+
}
|
|
37
|
+
if (x.earlier) {
|
|
38
|
+
lines.push(` asked before: declined ${x.earlier.kind} on \`${x.earlier.identifier}\`${x.earlier.decidedBy ? ` by ${x.earlier.decidedBy}` : ''} ${String(x.earlier.decidedAt).slice(0, 10)} — "${x.earlier.reason ?? ''}". That decision has lapsed.`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (pages.length) {
|
|
43
|
+
lines.push('', 'Pages this unit is being filed onto (candidates — only if a page is ABOUT the folder):')
|
|
44
|
+
for (const p of pages) lines.push(`- ${q(p.title)} (${p.tier}) — ref ${p.ref}${p.tier !== 'accessible' ? ' — needs confirmTier: true' : ''}`)
|
|
45
|
+
}
|
|
46
|
+
if (open.length) {
|
|
47
|
+
const example = open.slice(0, 3).map((x) => (pages[0]
|
|
48
|
+
? { identifier: x.identifier, claim: pages[0].ref }
|
|
49
|
+
: { identifier: x.identifier, decline: 'not_yet', reason: 'why it belongs to no page' }))
|
|
50
|
+
lines.push('', `Answer shape: folderDecisions: ${JSON.stringify(example)}`)
|
|
51
|
+
lines.push('No page fits? Author a small area page about the folder (`author`), then claim onto its ref. Generated/vendored/lockfiles/fixtures: decline "never".')
|
|
52
|
+
if (body?.cold) lines.push('You are a cold judge here: {identifier, defer: true} hands a question to the next session that touches it.')
|
|
53
|
+
}
|
|
54
|
+
return lines.join('\n')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** intake_materialize success: what the answers did. [] when nothing was asked. */
|
|
58
|
+
export function renderFolderDecisionsApplied(fd) {
|
|
59
|
+
const applied = Array.isArray(fd?.applied) ? fd.applied : []
|
|
60
|
+
if (!applied.length) return []
|
|
61
|
+
const lines = [`Folder decisions applied (${applied.length}):`]
|
|
62
|
+
for (const op of applied) {
|
|
63
|
+
if (op.action === 'claim') lines.push(` - claimed \`${op.identifier}\` onto ${q(op.page)} (${op.tier})`)
|
|
64
|
+
else if (op.action === 'decline') lines.push(` - declined ${op.kind} \`${op.identifier}\` — "${op.reason}"`)
|
|
65
|
+
else lines.push(` - deferred \`${op.identifier}\` to the next session that touches it`)
|
|
66
|
+
}
|
|
67
|
+
return lines
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** my_routing_claims / read_page: the declines, as lines. [] when there are none (or the server is older). */
|
|
71
|
+
export function renderDeclines(declines, { heading = 'Declines' } = {}) {
|
|
72
|
+
const list = Array.isArray(declines) ? declines : []
|
|
73
|
+
if (!list.length) return []
|
|
74
|
+
const lines = [`${heading} (${list.length}) — a decline covers the identifier and everything under it:`]
|
|
75
|
+
for (const d of list) {
|
|
76
|
+
const state = d.active ? (d.kind === 'never' ? 'never' : d.kind === 'not_yet' ? 'not yet' : 'snoozed') : `${d.kind}, lapsed — will be asked again`
|
|
77
|
+
lines.push(` ${d.active ? '⊘' : '·'} \`${d.identifier}\`${d.brain ? ` · ${d.brain}` : ''} — ${state}${d.reason ? ` — "${d.reason}"` : ''}${d.decidedBy ? ` · ${d.decidedBy}` : ''}${d.cold ? ' (cold judge)' : ''} · ${String(d.decidedAt).slice(0, 10)}`)
|
|
78
|
+
}
|
|
79
|
+
return lines
|
|
80
|
+
}
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
//
|
|
11
11
|
// Pure so CI can execute what each state prints.
|
|
12
12
|
|
|
13
|
+
import { renderDeclines } from './folder_decisions.mjs'
|
|
14
|
+
|
|
13
15
|
const q = (s) => `"${s}"`
|
|
14
16
|
const pageLabel = (h) => `${q(h.title)} (${h.kind}, ${h.tier})`
|
|
15
17
|
|
|
@@ -56,6 +58,8 @@ export function renderIdentifierResolution(out, { expand = false } = {}) {
|
|
|
56
58
|
if (mentions.length) {
|
|
57
59
|
lines.push(`Mentioned on (does not route): ${mentions.map((h) => q(h.title)).join(', ')}`)
|
|
58
60
|
}
|
|
61
|
+
// ADR-0077: a decline on it or a folder above it decides whether a commit is ASKED about it.
|
|
62
|
+
lines.push(...renderDeclines(out.declines, { heading: 'Declined' }))
|
|
59
63
|
const ev = out.events ?? { visibleCount: 0, recent: [] }
|
|
60
64
|
lines.push(`· ${ev.visibleCount} tagged timeline event${ev.visibleCount === 1 ? '' : 's'} visible to you${ev.recent?.length ? ':' : expand ? '.' : ' — pass expand: true to list recent ones.'}`)
|
|
61
65
|
for (const e of ev.recent ?? []) lines.push(` - ${String(e.occurredAt).slice(0, 10)} · ${e.source} · ${e.summary}`)
|
package/lib/server.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { fetchCortex, classify, resolveBase, resolveEnvToken, setSessionKey, set
|
|
|
10
10
|
import { REPORT_KINDS, REPORT_ISSUE_DESCRIPTION, fileIssue } from './report_issue.mjs'
|
|
11
11
|
import { folderClaimLine } from './folder_claims.mjs'
|
|
12
12
|
import { renderFolderClaimOffers, renderIdentifierResolution, renderUnroutedPathStamps } from './identifier_routes.mjs'
|
|
13
|
+
import { renderDeclines, renderFolderDecisionsApplied, renderFolderQuestions } from './folder_decisions.mjs'
|
|
13
14
|
import { resolveSessionKey, resolveLogSessionId } from './session_key.mjs'
|
|
14
15
|
import { runSendImessage } from './imessage_send.mjs'
|
|
15
16
|
import { formatGrepHits } from './grep_cli.mjs'
|
|
@@ -1225,7 +1226,8 @@ function renderNudge(payload) {
|
|
|
1225
1226
|
'Atomically publish a claimed intake item into one brain — the disclosure moment (ADR-0062). Deterministic identifier homes in that brain are always attached; documentIds may add further pages. The record is born at the strictest of its source baseline, what the producer asked for, and every attached page; a source floor (iMessage, claude-code) pins it. ' +
|
|
1226
1227
|
'Name the governing page with governingPage (one of documentIds, never a person page) — otherwise the ranking picks it. ' +
|
|
1227
1228
|
'Pass mode "preview" first when your choice differs from the claim\'s proposal: it returns the pages, the governing page and the tier this exact call would produce, and writes nothing. Never writes private intake into search/history before this call. ' +
|
|
1228
|
-
'⚠ ADR-0051: a unit does not finish until you looked for its OTHER homes. A call whose documentIds add nothing beyond the deterministic homes it gets anyway is REFUSED once — name the pages this unit is about (the design it implements, the project, the person), or go look, or say you looked with searchedForOtherHomes.'
|
|
1229
|
+
'⚠ ADR-0051: a unit does not finish until you looked for its OTHER homes. A call whose documentIds add nothing beyond the deterministic homes it gets anyway is REFUSED once — name the pages this unit is about (the design it implements, the project, the person), or go look, or say you looked with searchedForOtherHomes. ' +
|
|
1230
|
+
'⚠ ADR-0077: a GitHub commit or PR does not finish until every changed path has an answer. If a changed file\'s deepest folder (or, in a grab-bag folder like web/lib/engine/ or db/supabase/, the file itself) has no claim and no decline, the call is REFUSED with the open questions; answer each in folderDecisions and call again.',
|
|
1229
1231
|
inputSchema: {
|
|
1230
1232
|
intakeItemId: z.string().describe('intake item uuid'),
|
|
1231
1233
|
orgId: z.string().describe('destination brain org uuid'),
|
|
@@ -1250,6 +1252,17 @@ function renderNudge(payload) {
|
|
|
1250
1252
|
'looking, not a way past the question. Measured 2026-09-25: 30 records filed through this verb in one afternoon with no ' +
|
|
1251
1253
|
'judged page on any of them.',
|
|
1252
1254
|
),
|
|
1255
|
+
folderDecisions: z.array(z.object({
|
|
1256
|
+
identifier: z.string().describe('the open question\'s identifier, or a folder above it that its answerWith lists'),
|
|
1257
|
+
claim: z.string().optional().describe('page `ref:` (or document id) of a project page ABOUT this path — never the repo\'s mother page, a person or a user page'),
|
|
1258
|
+
decline: z.enum(['never', 'not_yet']).optional().describe('never = generated/build output, lockfiles, fixtures, vendored code; not_yet = asked again after 10 more commits or 90 days'),
|
|
1259
|
+
reason: z.string().optional().describe('required with decline: why it belongs to no page — the next session asked will read it'),
|
|
1260
|
+
defer: z.boolean().optional().describe('cold judges only (a cleanup lease): hand the question to the next session that touches it'),
|
|
1261
|
+
confirmTier: z.boolean().optional().describe('required to claim onto a page narrower than accessible — its tier will govern every future commit there'),
|
|
1262
|
+
})).optional().describe(
|
|
1263
|
+
'ADR-0077: one answer per open folder question from a refused call — exactly one of claim, decline or defer each. ' +
|
|
1264
|
+
'Send only after the server has listed the questions; claims and declines are written when the unit is filed.',
|
|
1265
|
+
),
|
|
1253
1266
|
},
|
|
1254
1267
|
},
|
|
1255
1268
|
async (args) => {
|
|
@@ -1273,10 +1286,18 @@ function renderNudge(payload) {
|
|
|
1273
1286
|
attachmentMeta: (args.documentIds ?? []).map(() => ({ origin: args.origin ?? 'llm' })),
|
|
1274
1287
|
...(args.governingPage ? { governingDocumentId: args.governingPage } : {}),
|
|
1275
1288
|
...(args.searchedForOtherHomes ? { searchedForOtherHomes: true } : {}),
|
|
1289
|
+
...(args.folderDecisions?.length ? { folderDecisions: args.folderDecisions } : {}),
|
|
1276
1290
|
}),
|
|
1277
1291
|
})
|
|
1278
1292
|
if (!res.ok) {
|
|
1279
1293
|
const body = await res.text()
|
|
1294
|
+
// ADR-0077: the forced folder question. Every refusal from it carries the open questions, so
|
|
1295
|
+
// print them in a form the judge can answer in ONE more call.
|
|
1296
|
+
{
|
|
1297
|
+
let parsed = null
|
|
1298
|
+
try { parsed = JSON.parse(body) } catch { /* not JSON */ }
|
|
1299
|
+
if (parsed && Array.isArray(parsed.questions)) return toolError(renderFolderQuestions(parsed))
|
|
1300
|
+
}
|
|
1280
1301
|
if (res.status === 409) {
|
|
1281
1302
|
let err = null
|
|
1282
1303
|
try { err = JSON.parse(body)?.error } catch { /* not JSON: fall through to the raw text */ }
|
|
@@ -1346,6 +1367,7 @@ function renderNudge(payload) {
|
|
|
1346
1367
|
// did not happen, which is exactly the silence this whole path exists to remove.
|
|
1347
1368
|
// ADR-0075 — the deepest unclaimed folder this unit sits in, offered for the feature page it was
|
|
1348
1369
|
// filed onto. Never claimed by the server; the session decides.
|
|
1370
|
+
lines.push(...renderFolderDecisionsApplied(body?.folderDecisions))
|
|
1349
1371
|
lines.push(...renderFolderClaimOffers(body?.folderClaimOffers))
|
|
1350
1372
|
if (body?.containerSkipped) {
|
|
1351
1373
|
lines.push(`⚠ CONTAINER NOT APPLIED — ${body.containerSkipped}. The record exists but is not inside the event you named; place it with contain_record or leave it out.`)
|
|
@@ -2427,22 +2449,27 @@ function renderNudge(payload) {
|
|
|
2427
2449
|
server.registerTool(
|
|
2428
2450
|
'snooze_routing_claim',
|
|
2429
2451
|
{
|
|
2430
|
-
title: '
|
|
2452
|
+
title: 'Decline an unclaimed source or path (never / not yet), or stop surfacing it',
|
|
2431
2453
|
description: "Silence one identifier in the `Sources nothing has claimed` block at session start. Use it when a recurring source genuinely belongs nowhere — a scratch repo, a bot channel, someone else's project that happens to cc you. NOT for something you simply have not got to yet: that is what leaving it alone does. A snooze silences the NOTICE and routes nothing; the events keep landing exactly where they land today. The block already has a volume floor that keeps one-off identifiers out, so anything you see there is recurring by construction — which is precisely why no threshold can tell 'not yet decided' from 'decided: nowhere', and why this exists. Bounded to at most a year and defaulting to 90 days, because a repo that was noise in August may be the centre of the work by November. Identity namespaces (`email:`, `thread:`) are refused: they are never surfaced as claimable in the first place, so there is nothing to snooze.",
|
|
2432
2454
|
inputSchema: {
|
|
2433
2455
|
identifier: z.string().describe('the identifier exactly as the context block prints it, e.g. `repo:owner/name`'),
|
|
2434
2456
|
brain: z.string().optional().describe('which brain to stop surfacing it in. Required when you belong to more than one — the call refuses rather than picking.'),
|
|
2435
2457
|
days: z.number().optional().describe('how long to stay quiet (1-365, default 90).'),
|
|
2436
|
-
reason: z.string().optional().describe('why it belongs nowhere, in one phrase — the next person to see it resurface will want this.'),
|
|
2458
|
+
reason: z.string().optional().describe('why it belongs nowhere, in one phrase — the next person to see it resurface will want this. REQUIRED with kind.'),
|
|
2459
|
+
kind: z.enum(['never', 'not_yet']).optional().describe('ADR-0077: record a DECLINE instead of silencing the notice. never = generated/build output, lockfiles, fixtures, vendored code (a cold judge — a session holding cleanup leases — may not write it); not_yet = asked again after 10 more commits touch it or 90 days. A decline covers the identifier and everything under it, and claiming the identifier clears it.'),
|
|
2460
|
+
remove: z.boolean().optional().describe('ADR-0077: UN-decline — delete the decline (or snooze) on this identifier, so the next commit that touches it is asked again.'),
|
|
2437
2461
|
},
|
|
2438
2462
|
},
|
|
2439
|
-
async ({ identifier, brain, days, reason }) => {
|
|
2463
|
+
async ({ identifier, brain, days, reason, kind, remove }) => {
|
|
2440
2464
|
let res
|
|
2441
2465
|
try {
|
|
2442
2466
|
res = await fetchCortex(`${BASE}/api/brain/snooze-routing-claim`, {
|
|
2443
2467
|
method: 'POST',
|
|
2444
2468
|
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
2445
|
-
body: JSON.stringify({
|
|
2469
|
+
body: JSON.stringify({
|
|
2470
|
+
identifier, ...(brain ? { brain } : {}), ...(days ? { days } : {}), ...(reason ? { reason } : {}),
|
|
2471
|
+
...(kind ? { kind } : {}), ...(remove ? { remove: true } : {}),
|
|
2472
|
+
}),
|
|
2446
2473
|
})
|
|
2447
2474
|
} catch (e) {
|
|
2448
2475
|
return toolError(`Could not snooze ${identifier}: ${e.message}`)
|
|
@@ -2453,7 +2480,10 @@ function renderNudge(payload) {
|
|
|
2453
2480
|
const hint = out?.hint ? `\n${out.hint}` : ''
|
|
2454
2481
|
return toolError(`Could not snooze ${identifier}: ${out?.error ?? res.status}${extra}${hint}`)
|
|
2455
2482
|
}
|
|
2456
|
-
|
|
2483
|
+
if (kind && !out?.kind) {
|
|
2484
|
+
return toolError(`This server cannot record a ${kind} decline yet (it stored a plain snooze instead). Re-run after the server updates.`)
|
|
2485
|
+
}
|
|
2486
|
+
return { content: [{ type: 'text', text: `${out.note}\nIf it should route somewhere after all, \`set_routing_identifier\` on the owning page overrides this — a claim always beats a decline, and clears it.` }] }
|
|
2457
2487
|
},
|
|
2458
2488
|
)
|
|
2459
2489
|
|
|
@@ -3844,7 +3874,7 @@ function renderNudge(payload) {
|
|
|
3844
3874
|
if (!res.ok) return toolError(`Could not read routing claims: ${out?.error ?? res.status}${out?.hint ? `\n${out.hint}` : ''}`)
|
|
3845
3875
|
|
|
3846
3876
|
const groups = Array.isArray(out?.identifiers) ? out.identifiers : []
|
|
3847
|
-
if (groups.length === 0) {
|
|
3877
|
+
if (groups.length === 0 && !(Array.isArray(out?.declines) && out.declines.length)) {
|
|
3848
3878
|
return { content: [{ type: 'text', text: 'No routing claims you can see. Nothing you own decides a brain for any identifier, so inbound mail resolves by nothing and stages.' }] }
|
|
3849
3879
|
}
|
|
3850
3880
|
const lines = []
|
|
@@ -3858,6 +3888,9 @@ function renderNudge(payload) {
|
|
|
3858
3888
|
lines.push(` ${c.brain} · ${page}${c.mine ? '' : ' · claimed by someone else'} · ${c.source} · ${String(c.createdAt).slice(0, 10)}`)
|
|
3859
3889
|
}
|
|
3860
3890
|
}
|
|
3891
|
+
// ADR-0077: declines beside claims.
|
|
3892
|
+
const declineLines = renderDeclines(out?.declines)
|
|
3893
|
+
if (declineLines.length) lines.push('', ...declineLines)
|
|
3861
3894
|
lines.push('')
|
|
3862
3895
|
lines.push('— Exactly one brain routes. Zero or several STAGE, and a real message carries several identifiers, so one clean sender can still stage on another key it carries.')
|
|
3863
3896
|
lines.push('— Before adding a claim: a second brain on the same identifier converts routing into staging. Claim the NARROWEST key the message carries (a repo or package), not the account it came from.')
|
package/package.json
CHANGED