@agenticprimitives/context 0.0.0-alpha.3 → 0.0.0-alpha.30
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 +2 -0
- package/dist/affiliations-read.d.ts +1 -1
- package/dist/affiliations-read.js +4 -4
- package/dist/affiliations-read.js.map +1 -1
- package/dist/ask-discovery.d.ts.map +1 -1
- package/dist/ask-discovery.js +3 -0
- package/dist/ask-discovery.js.map +1 -1
- package/dist/directory-rows.d.ts +2 -0
- package/dist/directory-rows.d.ts.map +1 -1
- package/dist/directory-rows.js +2 -1
- package/dist/directory-rows.js.map +1 -1
- package/dist/estate.d.ts +57 -0
- package/dist/estate.d.ts.map +1 -0
- package/dist/estate.js +43 -0
- package/dist/estate.js.map +1 -0
- package/dist/facts.d.ts +52 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +75 -0
- package/dist/facts.js.map +1 -0
- package/dist/grounded-composition.d.ts +1 -1
- package/dist/grounded-composition.d.ts.map +1 -1
- package/dist/grounded-composition.js +51 -0
- package/dist/grounded-composition.js.map +1 -1
- package/dist/grounded-types.d.ts +4 -0
- package/dist/grounded-types.d.ts.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/invitations-read.d.ts.map +1 -1
- package/dist/invitations-read.js +7 -4
- package/dist/invitations-read.js.map +1 -1
- package/dist/kb-question.d.ts.map +1 -1
- package/dist/kb-question.js +5 -0
- package/dist/kb-question.js.map +1 -1
- package/dist/kb-retrieve.d.ts +32 -0
- package/dist/kb-retrieve.d.ts.map +1 -0
- package/dist/kb-retrieve.js +73 -0
- package/dist/kb-retrieve.js.map +1 -0
- package/dist/membership-read.d.ts.map +1 -1
- package/dist/membership-read.js +10 -3
- package/dist/membership-read.js.map +1 -1
- package/dist/party-resolution.d.ts +81 -1
- package/dist/party-resolution.d.ts.map +1 -1
- package/dist/party-resolution.js +273 -62
- package/dist/party-resolution.js.map +1 -1
- package/dist/preferences.d.ts +39 -0
- package/dist/preferences.d.ts.map +1 -0
- package/dist/preferences.js +69 -0
- package/dist/preferences.js.map +1 -0
- package/dist/private-context.d.ts +13 -0
- package/dist/private-context.d.ts.map +1 -1
- package/dist/private-context.js +28 -10
- package/dist/private-context.js.map +1 -1
- package/dist/relationship-rows.d.ts +10 -0
- package/dist/relationship-rows.d.ts.map +1 -1
- package/dist/relationship-rows.js +4 -2
- package/dist/relationship-rows.js.map +1 -1
- package/dist/routines.d.ts +45 -0
- package/dist/routines.d.ts.map +1 -0
- package/dist/routines.js +34 -0
- package/dist/routines.js.map +1 -0
- package/dist/self-only.js +1 -1
- package/dist/self-only.js.map +1 -1
- package/dist/standing.d.ts +81 -7
- package/dist/standing.d.ts.map +1 -1
- package/dist/standing.js +164 -18
- package/dist/standing.js.map +1 -1
- package/dist/tiers.d.ts +6 -0
- package/dist/tiers.d.ts.map +1 -1
- package/dist/vault-question.d.ts +3 -0
- package/dist/vault-question.d.ts.map +1 -1
- package/dist/vault-question.js +55 -8
- package/dist/vault-question.js.map +1 -1
- package/package.json +20 -7
package/dist/party-resolution.js
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// people search is a different ask (279/338).
|
|
16
16
|
//
|
|
17
17
|
// So resolution now runs over `@agenticprimitives/context`: providers own a tier, the tier travels on every
|
|
18
|
-
// candidate, and a lookup that will bind an authority asks only the private ones.
|
|
19
|
-
//
|
|
18
|
+
// candidate, and a lookup that will bind an authority asks only the private ones. The naming registry is
|
|
19
|
+
// PUBLIC (spec 445 §3.6): it answers a typed name she wrote out, and fills the options of a question — it is
|
|
20
|
+
// never a candidate for a bare label. What else is public — `find_agents`, `get_agent` — answers QUESTIONS about who exists, which is a different thing a person can
|
|
20
21
|
// also want.
|
|
21
22
|
//
|
|
22
23
|
// The honest limit: the private tier reachable today is the asker's own relationships. Somebody known to
|
|
@@ -33,7 +34,7 @@ import { relationshipRows } from './relationship-rows.js';
|
|
|
33
34
|
/** The vault record type holding an asker's received resolution grants (spec 338). Declared HERE —
|
|
34
35
|
* the app's resolution-invitation module imports it back, so the key has one definition. */
|
|
35
36
|
export const RESOLUTION_GRANTS_RECORD = 'resolution.grants';
|
|
36
|
-
import { relationshipsProvider, rosterProvider } from './private-context.js';
|
|
37
|
+
import { relationshipsProvider, rosterProvider, exactNameProvider } from './private-context.js';
|
|
37
38
|
/** The roots a bare label might live under, most-likely first. A person is the common case for "alice". */
|
|
38
39
|
export const PARTY_ROOTS = ['me', 'org', 'team', 'treasury', 'workspace', 'svc', 'circle', 'church', 'registry'];
|
|
39
40
|
/** The owner a candidate was reached THROUGH, when it was reached through one.
|
|
@@ -53,43 +54,67 @@ const isAddress = (v) => /^0[xX][0-9a-fA-F]{40}$/.test(v);
|
|
|
53
54
|
* for is a question, not a resolution: a payment cannot be taken back. */
|
|
54
55
|
export const VALUE_ARGS = ONTOLOGY_VALUE_ARGS;
|
|
55
56
|
/**
|
|
56
|
-
*
|
|
57
|
+
* THE NAMING REGISTRY IS THE PUBLIC TIER (spec 352 §7, spec 445 §3.6 / audit H-12).
|
|
57
58
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* The rule: a name resolves in what the asker HOLDS, or it is a question. The naming registry is public and
|
|
60
|
+
* first-come — a hit for `alice.treasury` proves somebody registered that name, never that this person
|
|
61
|
+
* knows them — so it is never a candidate for a bare label. This block once argued the opposite ("PRIVATE
|
|
62
|
+
* tier, deliberately"), and that label is what made a name-squatter the payee of "send alice 10": the
|
|
63
|
+
* lookup asked for `tiers: ['private']` and was handed the registry.
|
|
64
|
+
*
|
|
65
|
+
* What the registry is still used for, each under its own name:
|
|
66
|
+
*
|
|
67
|
+
* A TYPED NAME SHE WROTE OUT (`alice.treasury`) — `exactNameProvider`, public tier, exact. She named the
|
|
68
|
+
* registry entry herself, so it resolves; the result says `evidence: 'typed-public-name'`. For an
|
|
69
|
+
* argument that moves value it is a question the first time (below).
|
|
70
|
+
*
|
|
71
|
+
* OPTIONS FOR A QUESTION — `publicNameOptions`. When nothing she holds answers to a bare label, the typed
|
|
72
|
+
* roots are read so the question can offer "alice.me — a public name, not someone you are linked to".
|
|
73
|
+
* It only ever fills a list a person chooses from; it is not a candidate and resolves nothing.
|
|
63
74
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name: f.name,
|
|
87
|
-
provenance: { tier: 'private', source: 'naming', ...(query.subject ? { subject: query.subject } : {}), match: label.includes('.') ? 'exact-name' : forms.length === 1 && forms[0] === label ? 'label' : 'close' },
|
|
88
|
-
}));
|
|
89
|
-
},
|
|
90
|
-
};
|
|
75
|
+
export async function publicNameOptions(raw, resolveName) {
|
|
76
|
+
const label = raw.trim().toLowerCase();
|
|
77
|
+
if (!label || isAddress(label) || label.includes('.'))
|
|
78
|
+
return [];
|
|
79
|
+
// A spoken name is words: "missio nexus organization" is registered, if at all, as `missio-nexus`
|
|
80
|
+
// or `missionexus` under a typed root — the kind word says which root to try first, and only that
|
|
81
|
+
// root when it was said.
|
|
82
|
+
const forms = /[^a-z0-9-]/.test(label) ? labelForms(label) : [label];
|
|
83
|
+
const kind = saidKind(label);
|
|
84
|
+
const saidRoot = kind === 'organization' || kind === 'organisation' ? 'org' : kind;
|
|
85
|
+
const roots = saidRoot && PARTY_ROOTS.includes(saidRoot) ? [saidRoot] : PARTY_ROOTS;
|
|
86
|
+
const names = forms.flatMap((f) => roots.map((r) => `${f}.${r}`));
|
|
87
|
+
const found = await Promise.all(names.map(async (name) => ({ name, agent: await resolveName(name).catch(() => null) })));
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
return found
|
|
90
|
+
.filter((f) => !!f.agent && !seen.has(f.agent.toLowerCase()) && !!seen.add(f.agent.toLowerCase()))
|
|
91
|
+
.map((f) => ({
|
|
92
|
+
agent: f.agent.toLowerCase(),
|
|
93
|
+
label: f.name,
|
|
94
|
+
name: f.name,
|
|
95
|
+
provenance: { tier: 'public', source: 'naming', match: forms.length === 1 && forms[0] === label ? 'label' : 'close' },
|
|
96
|
+
}));
|
|
91
97
|
}
|
|
92
|
-
/** The
|
|
98
|
+
/** The tiers a party lookup may read, decided by WHAT SHE TYPED: a bare label reads only her own tier; a
|
|
99
|
+
* typed name (it has a dot) may also be looked up, exactly, in the public naming registry. */
|
|
100
|
+
export function partyTiers(term) {
|
|
101
|
+
return term.trim().includes('.') ? ['private', 'public'] : ['private'];
|
|
102
|
+
}
|
|
103
|
+
/** Is this the registry entry she typed in full — public, exact, and backed by nothing she holds? */
|
|
104
|
+
const isTypedPublicName = (c) => c.provenance.tier === 'public' && c.provenance.source === 'naming' && c.provenance.match === 'exact-name';
|
|
105
|
+
/**
|
|
106
|
+
* DOES THE ASKER HOLD EVIDENCE THAT SHE MEANS THIS AGENT? (spec 445 §3.6, audit RUN-1 / RUNC-3.)
|
|
107
|
+
*
|
|
108
|
+
* Yes for a link in her own records — her relationships, her household, a resolution grant she was given.
|
|
109
|
+
* No for anything public, and no for a ROSTER row: a listing is what a member published about THEMSELVES
|
|
110
|
+
* (display name and handle alike), so any co-member can make themselves answer to "alice". That is enough
|
|
111
|
+
* to be a candidate for a message; for an argument that moves value it is a question.
|
|
112
|
+
*/
|
|
113
|
+
function heldByAsker(c) {
|
|
114
|
+
return c.provenance.tier === 'private' && c.provenance.source !== 'roster';
|
|
115
|
+
}
|
|
116
|
+
/** The providers a party lookup may consult, in order: her own tier, then the exact typed-name lookup —
|
|
117
|
+
* PUBLIC, and reached only by a lookup that names the public tier (`partyTiers`). */
|
|
93
118
|
export function partyProviders(lookups) {
|
|
94
119
|
const providers = [];
|
|
95
120
|
if (lookups.readSubjectRecord) {
|
|
@@ -99,13 +124,13 @@ export function partyProviders(lookups) {
|
|
|
99
124
|
providers.push(relationshipsProvider(tier), rosterProvider(tier));
|
|
100
125
|
}
|
|
101
126
|
if (lookups.resolveName)
|
|
102
|
-
providers.push(
|
|
127
|
+
providers.push(exactNameProvider(lookups.resolveName));
|
|
103
128
|
return providers;
|
|
104
129
|
}
|
|
105
130
|
/** Every agent the asker could mean by these words. Exported for tests and for a surface that wants to
|
|
106
131
|
* show the same candidates the resolver saw. */
|
|
107
132
|
export async function partyCandidates(raw, lookups, subject) {
|
|
108
|
-
const outcome = await resolveEntity(partyProviders(lookups), { term: raw, tiers:
|
|
133
|
+
const outcome = await resolveEntity(partyProviders(lookups), { term: raw, tiers: partyTiers(raw), ...(subject ? { subject } : {}), limit: 8 });
|
|
109
134
|
if (outcome.outcome === 'certain')
|
|
110
135
|
return [outcome.candidate];
|
|
111
136
|
return outcome.outcome === 'ambiguous' ? outcome.candidates : [];
|
|
@@ -263,7 +288,8 @@ export async function ownedAgentsOfType(owner, type, lookups, asker) {
|
|
|
263
288
|
const FOUND_IN = {
|
|
264
289
|
relationships: 'you are linked to them',
|
|
265
290
|
roster: 'a member of one of your organizations',
|
|
266
|
-
|
|
291
|
+
'resolution-grant': 'a way to reach them that you were given',
|
|
292
|
+
household: 'in your household',
|
|
267
293
|
};
|
|
268
294
|
/**
|
|
269
295
|
* What tells two agents with the same name apart. Kind first (a person and a team called the same thing
|
|
@@ -301,6 +327,7 @@ export async function householdMembers(subject, lookups) {
|
|
|
301
327
|
return {
|
|
302
328
|
agent: String(r.agent).toLowerCase(),
|
|
303
329
|
...(r.label ? { label: String(r.label) } : {}),
|
|
330
|
+
...(r.name ? { name: String(r.name) } : {}),
|
|
304
331
|
...(kin ? { kin } : {}), ...(kinLabel ? { kinLabel } : {}),
|
|
305
332
|
...(r.role ? { role: String(r.role) } : {}),
|
|
306
333
|
...(r.household ? { household: String(r.household) } : {}),
|
|
@@ -377,7 +404,11 @@ export function candidateHint(c) {
|
|
|
377
404
|
if (c.kind)
|
|
378
405
|
bits.push(c.kind);
|
|
379
406
|
bits.push(`${c.agent.slice(0, 8)}…${c.agent.slice(-4)}`);
|
|
380
|
-
|
|
407
|
+
// The registry is public: a name she typed in full is said to be exactly that, and one offered for a
|
|
408
|
+
// bare label is said to be nobody she is linked to (spec 445 §3.6).
|
|
409
|
+
const from = c.provenance.source === 'naming'
|
|
410
|
+
? (c.provenance.match === 'exact-name' ? 'the public name you typed' : 'a public name — not someone you are linked to')
|
|
411
|
+
: FOUND_IN[c.provenance.source];
|
|
381
412
|
if (from)
|
|
382
413
|
bits.push(from);
|
|
383
414
|
// A near name is SAID to be one: the person sees "closest to what you said" beside it before anything
|
|
@@ -395,6 +426,64 @@ async function rememberedChoice(lookups, where, value, candidates) {
|
|
|
395
426
|
return null;
|
|
396
427
|
return lookups.preferredChoice({ word: value, capability: where.capabilityId ?? where.toolId, arg: where.argName }, candidates).catch(() => null);
|
|
397
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Spec 420 §10 — THE NEAREST PERSON IN CONTEXT (`appr:namesResolveInContext`). Several candidates answer to a bare name;
|
|
431
|
+
* before asking, the resolver reads how near each is to the asker in the context she stands in: (1) on the roster of the
|
|
432
|
+
* ROOM she is asking in · (2) in her household · (3) in a context she shares (a roster of one of her organizations) ·
|
|
433
|
+
* (4) her recent dealings (how often they were a party in her recent turns) · (5) her other links. Exactly one at the
|
|
434
|
+
* nearest level that has any is the answer, CITED by that context; several at the same level stay a question — unless
|
|
435
|
+
* exactly one of them has recent dealings, which is then the answer, cited. Never a ranking score (ADR-0013): a level
|
|
436
|
+
* is a fact about the world ("on the team you are asking in"), and it is said.
|
|
437
|
+
*/
|
|
438
|
+
/** The typed-name suffix a recorded KIND claims: `person` → `me`, `org`/`organization` → `org`, a class IRI's local name → its
|
|
439
|
+
* suffix (ADR-0061). Empty when the kind is unknown — a kind is never guessed from a label. */
|
|
440
|
+
export function suffixForKind(k) {
|
|
441
|
+
const low = (k ?? '').toLowerCase();
|
|
442
|
+
if (!low)
|
|
443
|
+
return '';
|
|
444
|
+
if (low in CLASS_FOR_SUFFIX)
|
|
445
|
+
return low;
|
|
446
|
+
const byClass = Object.entries(SUFFIX_FOR_CLASS).find(([iri]) => iri.toLowerCase().endsWith(`#${low}agent`) || iri.toLowerCase().endsWith(`#${low}`));
|
|
447
|
+
return byClass?.[1] ?? { person: 'me', organization: 'org', service: 'svc' }[low] ?? '';
|
|
448
|
+
}
|
|
449
|
+
export function nearestInContext(candidates, ctx) {
|
|
450
|
+
const lc2 = (v) => v.toLowerCase();
|
|
451
|
+
const room = ctx.room ? lc2(ctx.room) : undefined;
|
|
452
|
+
const inHousehold = new Set((ctx.household ?? []).map((h) => lc2(h.agent)));
|
|
453
|
+
const dealings = new Map();
|
|
454
|
+
for (const r of ctx.recent ?? [])
|
|
455
|
+
dealings.set(lc2(r.agent), (dealings.get(lc2(r.agent)) ?? 0) + 1);
|
|
456
|
+
const levelOf = (c) => {
|
|
457
|
+
const a = lc2(c.agent);
|
|
458
|
+
if (room && c.provenance.context?.agent && lc2(c.provenance.context.agent) === room)
|
|
459
|
+
return { level: 1, because: `${c.provenance.context.name ? `on ${c.provenance.context.name}'s roster` : 'on the roster of the agent'} you are asking in` };
|
|
460
|
+
if (inHousehold.has(a) || c.provenance.source === 'household')
|
|
461
|
+
return { level: 2, because: 'in your household' };
|
|
462
|
+
if (c.provenance.source === 'roster')
|
|
463
|
+
return { level: 3, because: c.provenance.context?.name ? `on ${c.provenance.context.name} with you` : 'in an organization with you' };
|
|
464
|
+
if (dealings.has(a))
|
|
465
|
+
return { level: 4, because: `you dealt with them ${dealings.get(a)} time${dealings.get(a) === 1 ? '' : 's'} recently` };
|
|
466
|
+
// A typed name the naming service answers exactly (`ryan.me`) is not a context the asker stands in: it is the farthest
|
|
467
|
+
// reading, and it is said as one — the situation baseline (2026-09-28) had "drop ryan a line" reach a stranger's
|
|
468
|
+
// `ryan.me` over the Ryan on a team she stewards, cited "you are linked to them", which was false.
|
|
469
|
+
if (c.provenance.source === 'naming')
|
|
470
|
+
return { level: 6, because: 'an agent by that name, in no context you share' };
|
|
471
|
+
return { level: 5, because: 'you are linked to them' };
|
|
472
|
+
};
|
|
473
|
+
const levelled = candidates.map((c) => ({ c, ...levelOf(c) }));
|
|
474
|
+
const nearest = Math.min(...levelled.map((x) => x.level));
|
|
475
|
+
const atNearest = levelled.filter((x) => x.level === nearest);
|
|
476
|
+
if (atNearest.length === 1)
|
|
477
|
+
return { agent: lc2(atNearest[0].c.agent), candidate: atNearest[0].c, because: atNearest[0].because };
|
|
478
|
+
const dealt = atNearest.filter((x) => dealings.has(lc2(x.c.agent)));
|
|
479
|
+
if (dealt.length === 1) {
|
|
480
|
+
const n = dealings.get(lc2(dealt[0].c.agent));
|
|
481
|
+
return { agent: lc2(dealt[0].c.agent), candidate: dealt[0].c, because: `${dealt[0].because}, and you dealt with them ${n} time${n === 1 ? '' : 's'} recently` };
|
|
482
|
+
}
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
/** How a kind is said in a sentence (a person, an organization — never "a me", "a org"). */
|
|
486
|
+
const KIND_WORDS = { me: 'a person', org: 'an organization', svc: 'a service agent', household: 'a household', team: 'a team', treasury: 'a treasury', workspace: 'a workspace', circle: 'a circle', church: 'a church' };
|
|
398
487
|
export async function resolveParty(raw, lookups, where) {
|
|
399
488
|
const value = String(raw ?? '').trim();
|
|
400
489
|
if (isAddress(value)) {
|
|
@@ -495,9 +584,74 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
495
584
|
return chosen.value.agent;
|
|
496
585
|
}
|
|
497
586
|
}
|
|
498
|
-
|
|
499
|
-
|
|
587
|
+
// ── WHAT A VALUE ARGUMENT NEEDS BEHIND IT (spec 445 §3.6) ─────────────────────────────────────────
|
|
588
|
+
// For an argument that moves value, a candidate the asker holds no link to — a public name, a roster
|
|
589
|
+
// listing its member published — is ALWAYS a question, never a pick. Asked once: the question carries the
|
|
590
|
+
// spec-385 scope, the trusted resume that answers it is remembered, and `preferredChoice` then answers
|
|
591
|
+
// for the same word, capability and argument without asking.
|
|
592
|
+
const moves = VALUE_ARGS.has(where.argName);
|
|
593
|
+
const scope = { word: value, capability: where.capabilityId ?? where.toolId, arg: where.argName };
|
|
594
|
+
const confirmed = async (cands) => {
|
|
595
|
+
const remembered = await rememberedChoice(lookups, where, value, cands);
|
|
596
|
+
if (!remembered)
|
|
597
|
+
return null;
|
|
598
|
+
const c = cands.find((x) => x.agent.toLowerCase() === remembered.agent.toLowerCase());
|
|
599
|
+
lookups.onResolved?.({ arg: where.argName, raw: value, agent: remembered.agent.toLowerCase(), label: remembered.label ?? c?.label ?? remembered.agent, hint: `remembered: you chose “${remembered.label ?? c?.label ?? value}” for this before`, evidence: 'confirmed', ...(c && ownerOf(c) ? { ownedBy: ownerOf(c) } : {}) });
|
|
600
|
+
return remembered.agent.toLowerCase();
|
|
601
|
+
};
|
|
602
|
+
const askToConfirm = (prompt, cands, hintOf = candidateHint) => ask(prompt, {
|
|
603
|
+
name: where.argName, label: where.what, type: 'choice', required: true,
|
|
604
|
+
choices: cands.map((c) => ({ value: c.agent, label: c.label, hint: hintOf(c) })),
|
|
605
|
+
allowOther: true,
|
|
606
|
+
hint: 'nothing you hold links you to this — pick it to confirm, or give another name or address',
|
|
607
|
+
}, undefined, scope);
|
|
608
|
+
/** Why a lone candidate is a question for a value argument, said plainly. */
|
|
609
|
+
const unheld = (c) => isTypedPublicName(c)
|
|
610
|
+
? `“${value}” is a public name, and nothing you hold links you to it`
|
|
611
|
+
: `“${value}” is ${c.label}, known to you only through a listing they published`;
|
|
612
|
+
/** One candidate: use it — or, for a value argument she holds no link behind, the one she confirmed before, or ask. */
|
|
613
|
+
const settle = async (c) => {
|
|
614
|
+
if (moves && !heldByAsker(c)) {
|
|
615
|
+
const before = await confirmed([c]);
|
|
616
|
+
if (before)
|
|
617
|
+
return before;
|
|
618
|
+
askToConfirm(`${unheld(c)}. Is this who should be ${asVerb(where.what)}?`, [c]);
|
|
619
|
+
}
|
|
620
|
+
lookups.onResolved?.({ arg: where.argName, raw: value, agent: c.agent.toLowerCase(), label: c.label, hint: candidateHint(c), ...(ownerOf(c) ? { ownedBy: ownerOf(c) } : {}), ...(isTypedPublicName(c) ? { evidence: 'typed-public-name' } : {}) });
|
|
621
|
+
return c.agent.toLowerCase();
|
|
622
|
+
};
|
|
623
|
+
/** A decision made FOR her (nearest in context, the rolling window) may settle a value argument only on an agent she holds a link to. */
|
|
624
|
+
const mayDecide = (agent, among) => !moves || among.some((c) => c.agent.toLowerCase() === agent.toLowerCase() && heldByAsker(c));
|
|
625
|
+
// A BARE LABEL READS ONLY HER OWN TIER. A typed name she wrote out is also looked up, exactly, in the
|
|
626
|
+
// public registry (`partyTiers`) — a separate, named path, never a fallback for the label.
|
|
627
|
+
const found = await resolveEntity(partyProviders(lookups), {
|
|
628
|
+
term: value, tiers: partyTiers(value), ...(where.subject ? { subject: where.subject } : {}), limit: 8,
|
|
500
629
|
});
|
|
630
|
+
lookups.onCandidates?.({
|
|
631
|
+
arg: where.argName, raw: value, outcome: found.outcome,
|
|
632
|
+
...(found.outcome === 'unknown' ? { looked: found.looked.map((l) => l.source) } : {}),
|
|
633
|
+
candidates: (found.outcome === 'certain' ? [found.candidate] : found.outcome === 'ambiguous' ? found.candidates : []).map((c) => ({
|
|
634
|
+
agent: c.agent.toLowerCase(), source: c.provenance.source, ...(c.provenance.match ? { match: c.provenance.match } : {}),
|
|
635
|
+
...(c.provenance.context?.name ? { context: c.provenance.context.name } : {}), ...(c.kind ? { kind: c.kind } : {}),
|
|
636
|
+
})),
|
|
637
|
+
});
|
|
638
|
+
// Spec 420 §10 — HER HOUSEHOLD IS A CONTEXT TOO. Under `nearest`, a household member answering to the word (their label,
|
|
639
|
+
// their name's first part, a kin word) joins the candidates as a `household` source, so the nearest-in-context rule can
|
|
640
|
+
// prefer them over a farther context — "tell rich" at her own agent means the Rich she lives with, not a Rich on a team.
|
|
641
|
+
const outcome = await (async () => {
|
|
642
|
+
if (!where.nearest || !where.subject || isAddress(value) || value.includes('.'))
|
|
643
|
+
return found;
|
|
644
|
+
const w = value.toLowerCase();
|
|
645
|
+
const hh = (await householdMembers(where.subject, lookups).catch(() => [])).filter((m) => [m.label, m.kinWord, m.kinLabel].some((x) => x && x.toLowerCase() === w) || (m.label ?? '').toLowerCase().split(/[\s.]+/)[0] === w);
|
|
646
|
+
if (!hh.length)
|
|
647
|
+
return found;
|
|
648
|
+
const base = found.outcome === 'certain' ? [found.candidate] : found.outcome === 'ambiguous' ? found.candidates : [];
|
|
649
|
+
const merged = [...base];
|
|
650
|
+
for (const m of hh)
|
|
651
|
+
if (!merged.some((c) => c.agent.toLowerCase() === m.agent.toLowerCase()))
|
|
652
|
+
merged.push({ agent: m.agent.toLowerCase(), label: m.label ?? m.name ?? m.agent, ...(m.name ? { name: m.name } : {}), kind: 'person', provenance: { tier: 'private', source: 'household', subject: where.subject, match: 'label' } });
|
|
653
|
+
return merged.length === 1 ? { outcome: 'certain', candidate: merged[0] } : { outcome: 'ambiguous', candidates: merged };
|
|
654
|
+
})();
|
|
501
655
|
// ── WHAT KIND OF AGENT THIS ARGUMENT IS ──────────────────────────────────────────────────────────
|
|
502
656
|
// "Send money to nathan" and "send nathan a message" are the same word; the difference lives in the
|
|
503
657
|
// CAPABILITY, and the typed suffix (ADR-0061) is what makes it decidable. Tiers, in the order a person
|
|
@@ -508,11 +662,24 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
508
662
|
// is an answer, not a licence to quietly pay some other Nathan.
|
|
509
663
|
if (where.types?.length && (outcome.outcome === 'ambiguous' || outcome.outcome === 'certain')) {
|
|
510
664
|
const all = outcome.outcome === 'ambiguous' ? outcome.candidates : [outcome.candidate];
|
|
511
|
-
|
|
665
|
+
// A candidate with no typed name but a KNOWN kind still has a kind: a household member recorded by display name is a
|
|
666
|
+
// person (`.me`) — dropping every display-named candidate from the type tier asked "which person?" of the one Rich she lives with.
|
|
667
|
+
// A candidate with NEITHER is asked of the chain (`agentKindOf`), the record of what kind of agent it is — never guessed
|
|
668
|
+
// from the record that listed it (a roster lists people and teams alike).
|
|
669
|
+
if (lookups.agentKindOf)
|
|
670
|
+
await Promise.all(all.filter((c) => !(c.name ?? '').includes('.') && !c.kind).map(async (c) => { const k = await lookups.agentKindOf(c.agent).catch(() => null); if (k)
|
|
671
|
+
c.kind = k.toLowerCase(); }));
|
|
672
|
+
const suffix = (c) => { const n = (c.name ?? '').toLowerCase(); if (n.includes('.'))
|
|
673
|
+
return n.split('.').pop() ?? ''; if (c.kind)
|
|
674
|
+
return suffixForKind(c.kind) || c.kind; return (c.label ?? '').toLowerCase().split('.').pop() ?? ''; };
|
|
512
675
|
/** Ways the asker HOLDS that the gate refused, with the reason — collected as the tiers are tried. */
|
|
513
676
|
const heldButRefused = [];
|
|
514
677
|
for (const [rank, type] of where.types.entries()) {
|
|
515
|
-
|
|
678
|
+
// AN UNKNOWN KIND IS NOT THE WRONG KIND (spec 420 §10). A roster row that names a member by display name only, whose
|
|
679
|
+
// account records no type, is still a candidate for a person-shaped argument — dropping it let a stranger's typed
|
|
680
|
+
// `ryan.me` stand alone as the certain reading over the Ryan on her own team (situation baseline, 2026-09-28). It
|
|
681
|
+
// stays in the FIRST tier only, and never for an argument that moves value: money needs a KNOWN treasury.
|
|
682
|
+
const tier = all.filter((c) => suffix(c) === type || (rank === 0 && !VALUE_ARGS.has(where.argName) && c.provenance.source !== 'naming' && !(suffix(c) in CLASS_FOR_SUFFIX)));
|
|
516
683
|
// A SUBSTITUTION IS NOT A RESOLUTION. "Send alice 20 USDC" asks for her treasury; when nothing
|
|
517
684
|
// answers to one, paying her PERSON agent instead is a different destination reached silently — and
|
|
518
685
|
// a payment to the wrong address is not a thing anyone can undo. So for arguments that move value,
|
|
@@ -530,6 +697,20 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
530
697
|
for (const l of lists)
|
|
531
698
|
heldButRefused.push(...(l.refusals ?? []));
|
|
532
699
|
const owned = lists.flat().filter((c, i, xs) => xs.findIndex((y) => y.agent === c.agent) === i);
|
|
700
|
+
// WHOSE IT IS, FIRST (audit RUNC-3). Ownership is followed to an answer only from ONE agent she holds
|
|
701
|
+
// a link to. With several candidates, "exactly one of them has a treasury anyone can find" used to
|
|
702
|
+
// settle which Alice she meant — decided by who published a `charteredUnder` edge, which is the
|
|
703
|
+
// co-member who listed themselves as "Alice" as readily as her friend. For a value argument that is
|
|
704
|
+
// a question, and each choice says whose account it is and where that agent was found.
|
|
705
|
+
if (moves && owned.length && !(all.length === 1 && heldByAsker(all[0]))) {
|
|
706
|
+
const before = await confirmed(owned);
|
|
707
|
+
if (before)
|
|
708
|
+
return before;
|
|
709
|
+
const holder = (c) => { const i = lists.findIndex((l) => l.some((x) => x.agent === c.agent)); const o = all[i]; return o ? `held by ${o.label} (${FOUND_IN[o.provenance.source] ?? o.provenance.source})` : ''; };
|
|
710
|
+
askToConfirm(all.length > 1
|
|
711
|
+
? `${all.length} agents answer to “${value}”. Which ${type} should be ${asVerb(where.what)}?`
|
|
712
|
+
: `${unheld(all[0])}. Is their ${type} the one that should be ${asVerb(where.what)}?`, owned, (c) => [candidateHint(c), holder(c)].filter(Boolean).join(' · '));
|
|
713
|
+
}
|
|
533
714
|
if (owned.length === 1) {
|
|
534
715
|
const c = owned[0];
|
|
535
716
|
lookups.onResolved?.({ arg: where.argName, raw: value, agent: c.agent, label: c.label, hint: candidateHint(c), ...(ownerOf(c) ? { ownedBy: ownerOf(c) } : {}) });
|
|
@@ -574,11 +755,8 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
574
755
|
: `ask ${value} for a way to pay their ${where.types[0]}`,
|
|
575
756
|
});
|
|
576
757
|
}
|
|
577
|
-
if (tier.length === 1)
|
|
578
|
-
|
|
579
|
-
lookups.onResolved?.({ arg: where.argName, raw: value, agent: c.agent.toLowerCase(), label: c.label, hint: candidateHint(c), ...(ownerOf(c) ? { ownedBy: ownerOf(c) } : {}) });
|
|
580
|
-
return c.agent.toLowerCase();
|
|
581
|
-
}
|
|
758
|
+
if (tier.length === 1)
|
|
759
|
+
return settle(tier[0]);
|
|
582
760
|
if (tier.length > 1) {
|
|
583
761
|
// THE ONE THEY CONFIRMED FOR THIS, DURABLY (spec 385): the scoped preference outranks the rolling
|
|
584
762
|
// window, revalidated against these candidates; evidence, never a grant.
|
|
@@ -588,11 +766,18 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
588
766
|
return remembered.agent.toLowerCase();
|
|
589
767
|
}
|
|
590
768
|
// THE ONE THEY CHOSE LAST TIME (spec 370 P7): the same words, settled on one of these before.
|
|
591
|
-
const
|
|
592
|
-
|
|
769
|
+
const recentForTier = lookups.recentParties ? await lookups.recentParties().catch(() => []) : [];
|
|
770
|
+
const before = chosenBefore(value, tier, recentForTier);
|
|
771
|
+
if (before && mayDecide(before.agent, tier)) {
|
|
593
772
|
lookups.onResolved?.({ arg: where.argName, raw: value, agent: before.agent.toLowerCase(), label: before.label ?? before.agent, hint: `remembered: the “${value}” you chose last time` });
|
|
594
773
|
return before.agent.toLowerCase();
|
|
595
774
|
}
|
|
775
|
+
// Spec 420 §10 — the nearest in context, before asking.
|
|
776
|
+
const nearTier = where.nearest ? nearestInContext(tier, { ...(where.room ? { room: where.room } : {}), household: where.subject ? await householdMembers(where.subject, lookups).catch(() => []) : [], recent: recentForTier }) : null;
|
|
777
|
+
if (nearTier && mayDecide(nearTier.agent, tier)) {
|
|
778
|
+
lookups.onResolved?.({ arg: where.argName, raw: value, agent: nearTier.agent, label: nearTier.candidate.label, hint: candidateHint(nearTier.candidate), because: nearTier.because, ruleId: 'nearest-in-context', pointId: 'party.nearest' });
|
|
779
|
+
return nearTier.agent;
|
|
780
|
+
}
|
|
596
781
|
ask(`Which “${value}” do you mean?`, {
|
|
597
782
|
name: where.argName, label: where.what, type: 'choice', required: true,
|
|
598
783
|
choices: tier.map((c) => ({ value: c.agent, label: c.label, hint: candidateHint(c) })),
|
|
@@ -617,15 +802,21 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
617
802
|
// last dot is "missio nexus", which is a name, not a kind, and reading it as one asked "which org should
|
|
618
803
|
// be the organization?" of the one organization called that (caught live, 2026-09-08).
|
|
619
804
|
const knownSuffix = (v) => { const sfx = (v ?? '').toLowerCase().split('.').pop() ?? ''; return v?.includes('.') && sfx in CLASS_FOR_SUFFIX ? sfx : ''; };
|
|
620
|
-
const
|
|
621
|
-
return ''; if (low in CLASS_FOR_SUFFIX)
|
|
622
|
-
return low; const byClass = Object.entries(SUFFIX_FOR_CLASS).find(([iri]) => iri.toLowerCase().endsWith(`#${low}agent`) || iri.toLowerCase().endsWith(`#${low}`)); return byClass?.[1] ?? { person: 'me', organization: 'org', service: 'svc' }[low] ?? ''; };
|
|
623
|
-
const certainSuffix = knownSuffix(c.name) || kindOf(c.kind);
|
|
805
|
+
const certainSuffix = knownSuffix(c.name) || suffixForKind(c.kind);
|
|
624
806
|
if (where.types?.length && certainSuffix && !where.types.includes(certainSuffix)) {
|
|
807
|
+
// A READ (no capability) about an agent of another kind resolves to that agent: the read says what it finds
|
|
808
|
+
// ("missio-nexus.org holds no treasury, and balances are kept only in treasuries") — asking "which treasury?" of a
|
|
809
|
+
// question is a worse answer than the true one. An ACT still asks: nothing is done to the wrong kind.
|
|
810
|
+
if (!where.capabilityId) {
|
|
811
|
+
lookups.onResolved?.({ arg: where.argName, raw: value, agent: c.agent.toLowerCase(), ...(c.label ? { label: c.label } : {}), hint: `${c.label ?? c.agent} — ${KIND_WORDS[certainSuffix] ?? `a ${certainSuffix}`}` });
|
|
812
|
+
return c.agent.toLowerCase();
|
|
813
|
+
}
|
|
625
814
|
const want = where.types[0];
|
|
626
|
-
ask(`“${value}” is ${c.label ?? c.agent}, ${certainSuffix
|
|
815
|
+
ask(`“${value}” is ${c.label ?? c.agent}, ${KIND_WORDS[certainSuffix] ?? `a ${certainSuffix}`}${VALUE_ARGS.has(where.argName) ? ', and money moves only between treasuries' : ''} — which ${want} should be ${asVerb(where.what)}?`, {
|
|
627
816
|
name: where.argName, label: where.what, type: 'address', required: true,
|
|
628
|
-
|
|
817
|
+
// A typed name has ONE label (ADR-0061: `<label>.<type>`), so the example is the label with the wanted suffix — never
|
|
818
|
+
// `missio-nexus.org.treasury`.
|
|
819
|
+
hint: `a ${want} name (${value.split('.')[0]}.${want}) or its address — nothing of theirs answered to one`,
|
|
629
820
|
}, {
|
|
630
821
|
label: `Ask ${value} for a way to reach their ${want}`,
|
|
631
822
|
message: where.pendingAmount
|
|
@@ -633,15 +824,28 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
633
824
|
: `ask ${value} for a way to pay their ${want}`,
|
|
634
825
|
});
|
|
635
826
|
}
|
|
636
|
-
|
|
637
|
-
return c.agent.toLowerCase();
|
|
827
|
+
return settle(c);
|
|
638
828
|
}
|
|
639
829
|
if (outcome.outcome === 'unknown') {
|
|
830
|
+
// NOTHING SHE HOLDS ANSWERS — and that is the answer (ADR-0013): no public hit becomes the party. What
|
|
831
|
+
// the registry may do is fill the QUESTION: the typed names this label is registered under are offered,
|
|
832
|
+
// each said to be public, and she picks or types another. The one she confirmed before for this word,
|
|
833
|
+
// capability and argument (spec 385) is the only way one of them is used without asking.
|
|
834
|
+
const registered = lookups.resolveName ? await publicNameOptions(value, lookups.resolveName).catch(() => []) : [];
|
|
835
|
+
const sfx = (c) => (c.name ?? '').split('.').pop() ?? '';
|
|
836
|
+
// Money needs a treasury; anything else, a kind the capability takes.
|
|
837
|
+
const options = !where.types?.length ? registered : registered.filter((c) => (moves ? sfx(c) === where.types[0] : where.types.includes(sfx(c))));
|
|
838
|
+
if (options.length) {
|
|
839
|
+
const before = await confirmed(options);
|
|
840
|
+
if (before)
|
|
841
|
+
return before;
|
|
842
|
+
askToConfirm(`I could not find “${value}” among the agents you know. ${options.length === 1 ? 'One public name answers' : `${options.length} public names answer`} to it — is ${options.length === 1 ? 'that' : 'one of them'} who you mean?`, options);
|
|
843
|
+
}
|
|
640
844
|
// Say where we looked. "I could not find them" without that leaves a person correcting the wrong thing.
|
|
641
845
|
const said = {
|
|
642
846
|
relationships: 'the agents you are linked to',
|
|
643
847
|
roster: 'the members of your organizations',
|
|
644
|
-
naming: 'the
|
|
848
|
+
naming: 'the public name registry',
|
|
645
849
|
};
|
|
646
850
|
const where_ = [...new Set(outcome.looked.map((l) => said[l.source] ?? l.source))].join(', ');
|
|
647
851
|
ask(`I could not find “${value}”. Which agent do you mean?`, {
|
|
@@ -667,9 +871,16 @@ export async function resolveParty(raw, lookups, where) {
|
|
|
667
871
|
lookups.onResolved?.({ arg: where.argName, raw: value, agent: remembered.agent.toLowerCase(), label: remembered.label ?? remembered.agent, hint: `remembered: you chose “${remembered.label ?? value}” for this before` });
|
|
668
872
|
return remembered.agent.toLowerCase();
|
|
669
873
|
}
|
|
874
|
+
// Spec 420 §10 — the nearest in context, before asking.
|
|
875
|
+
const recentAll = lookups.recentParties ? await lookups.recentParties().catch(() => []) : [];
|
|
876
|
+
const near = where.nearest ? nearestInContext(candidates, { ...(where.room ? { room: where.room } : {}), household: where.subject ? await householdMembers(where.subject, lookups).catch(() => []) : [], recent: recentAll }) : null;
|
|
877
|
+
if (near && mayDecide(near.agent, candidates)) {
|
|
878
|
+
lookups.onResolved?.({ arg: where.argName, raw: value, agent: near.agent, label: near.candidate.label, hint: candidateHint(near.candidate), because: near.because, ruleId: 'nearest-in-context', pointId: 'party.nearest' });
|
|
879
|
+
return near.agent;
|
|
880
|
+
}
|
|
670
881
|
if (lookups.recentParties) {
|
|
671
882
|
const before = chosenBefore(value, candidates, await lookups.recentParties().catch(() => []));
|
|
672
|
-
if (before) {
|
|
883
|
+
if (before && mayDecide(before.agent, candidates)) {
|
|
673
884
|
lookups.onResolved?.({ arg: where.argName, raw: value, agent: before.agent.toLowerCase(), label: before.label ?? before.agent, hint: `remembered: the “${value}” you chose last time` });
|
|
674
885
|
return before.agent.toLowerCase();
|
|
675
886
|
}
|